x86 DLL Works But Not x64 DLL

风流意气都作罢 提交于 2019-12-08 03:24:03

问题


I'm trying to include System.Data.SQLite with my project which is coded in C# and uses .NET Framework v4. I'm a little confused... I'm running Windows 8.1 x64 and the platform target for the project is set to Any CPU. If I include the x64 version of System.Data.SQLite.dll then I get an error saying The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' (are you missing an assembly reference?). However, if I include the x86 version of System.Data.SQLite.dll then it compiles fine. Shouldn't it be the other way around (shouldn't the x86 version not compile)? Since the x86 version works, then can I include just the x86 version with the compiled project? If I need to include both the x86 and x64 version of System.Data.SQLite.dll (as well as SQLite.Interop.dll) then how might I go about doing that? I should also note the version of System.Data.SQLite is v1.0.94.0 (and is for .NET Framework 4).


回答1:


Unless you need the x64 version you can include just the x86 version and build your project as x86. This is safe for most projects, unless you need the 64-bit address space.

You should use AnyCPU only when your app is purely managed and doesn't have any dependencies on a specific architecture. When using native code such as SQLite the app should always set the specific platform target.

The reason the x86 version of SQLite works rather than the x64 is that in modern versions of Visual Studio the AnyCPU configuration defaults to /platform:anycpu32bitpreferred rather than to /platform:anycpu. With anycpu32bitpreferred the app will use 32-bit mode if possible and will use 64-bit mode only if 32-bit mode is not available.




回答2:


For such cases, there's no better technology than Nuget ! You can use directly the SqlLite nuget package, which is explicitly compatible for x86/x64. I tried it in AnyCpu, x86 and x64, and I have no compilation error at all in both cases.

So you just have to remove your old references, and right-click on the project references, and choose "Manage NuGet Packages", then search for System.Data.SQLite.

And moreover, you will be forever up-to-date :)



来源:https://stackoverflow.com/questions/28734610/x86-dll-works-but-not-x64-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!