Reputation: 2437
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).
Upvotes: 1
Views: 912
Reputation: 7320
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 :)
Upvotes: 1
Reputation: 21899
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.
Upvotes: 8