Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite with "any cpu" compile option [ crash on 64 bit machine when unchecked "prefer 32 bit" option ]

Tags:

c#

.net

sqlite

I just follow the instruction at

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

and I can able to compile sample C# appliation with

"any cpu"

option.

But when I run application, if I choose

"prefer 32 bit"

option, my application crash:

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

If I uncheck "prefer 32 bit" option it works fine on my 64 bit machine.

Why this happen?Any suggestion to fix it?

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' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op) at System.Data.SQLite.SQLite3.StaticIsInitialized() at System.Data.SQLite.SQLiteLog.Initialize() at System.Data.SQLite.SQLiteFactory..cctor() --- End of inner exception stack trace --- at System.Data.SQLite.SQLiteFactory..ctor()

PS 3:

I notice an interesting thing. Although at visual studio it craches, when i run my program exe, by just clicking it, it works.

like image 466
Hippias Minor Avatar asked Jul 24 '13 12:07

Hippias Minor


1 Answers

Run command prompt as Administrator. cd into the directory with your x64 .dll. Then type: gacutil -i SQLite.Interop.dll. Then cd to the directory with the x86 .dll. Type again: gacutil -i SQLite.Interop.dll. Now it should be working right.

What this does is installs each assembly into the GAC(Global Assembly Cache) on your system. It puts them into the proper system cache directory depending on how it was compiled(x86 or x64). This should only be used for debugging purposes.

GAC 32bit vs. 64bit

For a client machine. Do a deployment for x86 and for x64 each. Of course throw in the proper version of your .dll for each.

like image 118
user1132959 Avatar answered Nov 09 '22 21:11

user1132959