7

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.

Hippias Minor
  • 1,917
  • 2
  • 21
  • 46
  • 1
    Debug your application and find out what this returns: System.IO.Directory.GetCurrentDirectory(); This is where your .dll will probably have to be. – user1132959 Jul 24 '13 at 14:05
  • Well it gives the my bin directory in debug mode F:\TestWorkSpace\SQLiteTest\bin\Debug and there is x86 folder which has SQLite.Interop.dll. SQLite says it will look at x86 folder – Hippias Minor Jul 24 '13 at 14:10
  • When I debug, Although I choose "perefer 32 bit"...It try to load under x64. "Trying to load native SQLite library "F:\TestWorkSpace\SQLiteTest\bin\Debug\x64\SQLite.Interop.dll"..." – Hippias Minor Jul 24 '13 at 14:15
  • Try putting the 32-bit SQLite.Interop.dll in the \bin\Debug\ directory. It must see that you are still on a 64-bit machine so it tries to run the 64-bit one but can't since it is a 32-bit process? – user1132959 Jul 24 '13 at 14:18
  • In that case it works. But I wanted to compile it both x86 and x64.If it was x86 it should look x86 folder if it is x64 should look x64 – Hippias Minor Jul 24 '13 at 14:20
  • Sounds like a job for GAC. I'll post an answer – user1132959 Jul 24 '13 at 14:23

1 Answers1

3

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.

Community
  • 1
  • 1
user1132959
  • 978
  • 8
  • 16
  • 1
    I do not want to install them to GAC. I want simple embedded database with no installation-configuraton.So I choose SQLite – Hippias Minor Jul 24 '13 at 14:29
  • GAC is for debugging purposes, I made the proper edit. You want a simple database for clients or for yourself? – user1132959 Jul 24 '13 at 14:31
  • 1
    For clients and me . So using GAC is bad idea. I have lots of problem with it before. – Hippias Minor Jul 24 '13 at 14:34
  • For clients you will have to deploy 2 versions of the software right? 64-bit and 32-bit? For debugging GAC works well. For clients you can deploy your software with the proper version of SQLite.Interop.dll in the same directory the App will run from, or you can choose one the options listed here: http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.80).aspx – user1132959 Jul 24 '13 at 14:41
  • No just one deployment.[ any cpu] if installed on 32 bit will use x86 and if on x64 will use x64.no other config. – Hippias Minor Jul 24 '13 at 14:43
  • If you want just one deployment, it will have to be x86 to run on both 32-bit and 64-bit. You will have to deploy it for each if you want what you're looking for. You would need a dynamic installer to not do multiple deployments. Either way the end installation will end up the same. Most software packages come in both flavors, for example, java. http://java.com/en/download/index.jsp If I were you I would do 2 deployments. – user1132959 Jul 24 '13 at 14:49
  • You may be right. But for now, My First purpose is, if possible use sqlite with any cpu option without GAC. – Hippias Minor Jul 24 '13 at 14:52
  • No problem. But I'm pretty sure it's not possible to do what you're looking for. Look here 2nd answer. http://stackoverflow.com/questions/6503634/64-bit-sqlite-dll-and-any-cpu?rq=1 You must choose x86 or x64 or if you do choose Any CPU you have to use GAC. – user1132959 Jul 24 '13 at 15:02
  • Actually it works. The strange thing is that when i run my compiled program by just clicking it instead of visual studio debug, it works.It creashed under visual studio execution – Hippias Minor Jul 24 '13 at 15:05
  • That's because your working directory is the directory you launched it from, and it searches there. However, launching from visual studio will give you a different working directory(/bin/Debug or /bin/Release), hence the need for putting the .dlls in the GAC. Not easy to debug a progam you clicked on instead of running in visual studio. – user1132959 Jul 24 '13 at 15:10