0

Error message:

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

I did search a lot on this error and got some solutions to this problem but non of them is helping me to solve the error.

When I code to connect to Sqlite database with 64-bit compatibility all goes well but I'm unable to solve the error for 32-bit compatibility used using NuGet package:

using system.data.SQlite

I'm unable to do a large code yet, I just count the record present in a table in Sqlite database.

Any help will be appreciated!

PS: Sorry for making a new thread on the same question (if I actually did).

  • 1
    Did you trying looking into this. It seems a possible duplicate https://stackoverflow.com/questions/1278929/could-not-load-file-or-assembly-system-data-sqlite – Shahid Manzoor Bhat Jan 24 '19 at 07:53
  • I ran into an issue with `SQLite` where I had to include the nuget package in the projects the referenced the project that used it. Wpf app referenced a class library that referenced SQLite. Adding SQLite to the Wpf app solved the issue. – fstam Jan 24 '19 at 09:11
  • ya i checked that but non of the solution works – Soham Jain Jan 24 '19 at 10:41
  • i added SQLite to my project and its working fine with 64bit compatibility but showing error in 32bit compatibility @fstam – Soham Jain Jan 24 '19 at 10:43
  • @user5377037 i try all the given solution of that thread , but still i didnt get the solution – Soham Jain Jan 24 '19 at 12:50

1 Answers1

1

If we build our C# application into x86 assembly, then we run it on x64 Windows machine. We will have a problem. On customers/target 64-bit machines, because out executable that starts the process consists entirely of managed code, it will run with the native processor architecture of the machine, which will be x64 on an x64 machine. Later on, this will cause assemblies containing any native code compiled for x86 (e.g. the System.Data.SQLite.dll mixed-mode assembly, the SQLite.Interop.dll native interop assembly, or the sqlite3.dll native library) to fail to load, typically resulting in a BadImageFormatException being thrown based on.

Your Project Folder Structure :

<bin>\App.exe (required, managed-only application executable assembly)
<bin>\App.dll (optional, managed-only application library assembly)
<bin>\System.Data.SQLite.dll (required, managed-only core assembly)
<bin>\x86\SQLite.Interop.dll (required, x86 native interop assembly)
<bin>\x64\SQLite.Interop.dll (required, x64 native interop assembly)

Edit :

Note: You'll find the Interop DLLs in the binary zip file for the .NET target, on which you'r working.

Useful References :

1) SQLite configuration for C# application targeting any CPU

2) SQLite dll for x86/x64 architectures

3) Using SQLite With C#

4) Options for using System.Data.SQLite in a 32bit and 64bit C# world

  • first of all thanks for ur time , i have 1 question SQLite.Interop.dll is same or different for x86 and x64?, if yes then can u pls provide me link to download them, and how can we place same file name in same dictionary ?, – Soham Jain Jan 24 '19 at 13:38
  • `SQLite.Interop.dll` will be different for x86 and x64 and the directory will also be different. I edited answer see project structure. –  Jan 24 '19 at 13:50
  • tried but still not working....am i doing something wrong?.....i just created 2 directory in debug folder with x86 and x64 name, and past the interop.dll in them ...but still i m getting error, forgive me if i m doing something wrong , and asking for help again and again – Soham Jain Jan 25 '19 at 06:27
  • You need to check it yourself because above is the provided solution for your question. –  Jan 25 '19 at 12:25