SQLite with the option to compile "any cpu" [crash on a 64-bit machine when unchecking the "prefers 32-bit" option)

I just follow the instructions in

SQLite-on-Visual-Studio-with-NuGet-and-Easy-Instructions

and I can compile a C # c sample

"any cpu"

option.

But when I run the application, if I choose

32 bit preferred

my application crashes:

"Unable to load DLL" SQLite.Interop.dll "

If I uncheck the β€œprefer 32 bit” option, it works fine on my 64-bit machine.

Why is this happening? Any suggestion to fix this?

PS: I use 64-bit Windows 8. and I provide [x86] and [x64] folders for SQLite.

PS 1: Error:

System.TypeInitializationException: The type initializer for "System.Data.SQLite.SQLiteFactory" made an exception. ---> System.DllNotFoundException: Unable to load DLL "SQLite.Interop.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E) in System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none (SQLiteConfigOpsEnum op) in System.Data.SQLite.SQLite3.StaticIsInitialized () in System.Data.SQLite.SQLiteLog.Initialize. SQLite.SQLiteFactory..cctor () --- End of internal check for exception stack --- in System.Data.SQLite.SQLiteFactory..ctor ()

PS 3:

I notice an interesting thing. Although it pops up in the visual studio when I launch my exe program, just by clicking on it, it works.

+6
source share
1 answer

Run the command line as an administrator. cd to the directory with your x64.dll. Then type: gacutil -i SQLite.Interop.dll . Then cd to the directory with x86.dll. Type again: gacutil -i SQLite.Interop.dll . Now it should work correctly.

This means that every assembly is installed in the GAC (global assembly cache) on your system. It puts them in the appropriate system cache directory depending on how it was compiled (x86 or x64). This should be used for debugging purposes only.

GAC 32bit vs 64bit

For the client machine. Do the deployment for x86 and for x64 each. Of course, enter the appropriate version of your .dll for each.

+3
source

Source: https://habr.com/ru/post/950184/


All Articles