38

I've broken the code down to the smallest possible statement:

Dim cn As System.Data.SQLite.SQLiteConnection

And I get the following error when calling the code from a WinForm applicaiton:

System.BadImageFormatException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139'

Yet calling the same piece of code from MS Unit Test I do not get the error, plus the full code set works as expected.

bhavinb
  • 3,278
  • 2
  • 28
  • 26
Tim Murphy
  • 4,892
  • 4
  • 40
  • 48
  • See similar http://stackoverflow.com/questions/11370344/could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-a?lq=1 – Michael Freidgeim May 20 '13 at 21:34

3 Answers3

61

SQLite contains unmanaged code, you can't run it on a 64-bit operating system unless you deploy the 64-bit version. Quick fix: Project + Properties, Build tab, Platform Target = x86.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
4

Make sure you use correct assembly with respect to 32 and 64 bits.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
2

I solved the problem by downloading a new version of the SQLite DLL via NuGet: http://gurustop.net/blog/2011/05/19/sqlite-database-nuget-package-common-problems-solved/

Denis
  • 833
  • 3
  • 12
  • 22