0

I am working on a project using SQLite - getting above error when trying to open the Connection, using SQLite for the first time.

Followed below links amongst others but error still persists - any pointers appreciated

Visual Studio C# - SQLite.Interop.dll not found

Unable to load DLL 'SQLite.Interop.dll'

Package.config

<packages>
<package id="EntityFramework" version="6.4.4" targetFramework="net471"/>
<package id="System.Data.SQLite" version="1.0.112.2"targetFramework="net471" />
<package id="System.Data.SQLite.Core" version="1.0.112.2"targetFramework="net471" />
<package id="System.Data.SQLite.EF6" version="1.0.112.2"targetFramework="net471" />
<package id="System.Data.SQLite.Linq" version="1.0.112.2"targetFramework="net471" />
</packages>

Now getting below Error:- BadImageFormatException

It's any CPU

enter image description here

Ram
  • 527
  • 1
  • 10
  • 26

1 Answers1

0

Your post-build step is wrong, I think. You should copy the folder x86, not only its contents. Also, since presumably your application runs in 64 bit mode, you also need to copy the x64 folder. So in the end, you have two folders x86 and x64 below the folder with your main executable, both of them containing a file called SQLite.interop.dll.

PMF
  • 14,535
  • 3
  • 23
  • 49
  • I will try that and see if that fixes the problem – Ram Feb 10 '22 at 08:36
  • Amended the post0build step to include x64 but same error persists – Ram Feb 10 '22 at 09:11
  • That is weird. What exact target framework are you using? – PMF Feb 10 '22 at 11:42
  • .NET Framework 4.7.1 – Ram Feb 10 '22 at 11:45
  • I'm using version 1.0.115 and .NET 4.8, but otherwise this works for me. Are you sure the working directory of your application is correct? – PMF Feb 10 '22 at 12:42
  • It is correct - this is really driving me crazy! – Ram Feb 10 '22 at 16:50
  • Have you tried checking whether there's really a dependency issue with the dll? Use a tool such as https://github.com/lucasg/Dependencies/releases/tag/v1.11.1 to check for dependeny problems. – PMF Feb 11 '22 at 06:05
  • used the tool and got it to work - then found out I have to use an older version - now getting BadImageFormatException - uploaded in main post – Ram Feb 11 '22 at 16:46
  • That is typically the result of trying to load a 32 bit dll into a 64 bit process or vice-versa. Is your application 32 bit, 64 bit or AnyCpu? – PMF Feb 11 '22 at 17:02
  • it's any CPU - updated post with new package.config pointing to older version – Ram Feb 12 '22 at 13:28
  • Try whether you get it to run if you set it explicitly to 32 or 64 bit. If either of them works, you should get a hint on what could be wrong. – PMF Feb 12 '22 at 13:41
  • Tried all 3 and same error – Ram Feb 12 '22 at 14:20
  • It could be that the dll's are corrupted – Ram Feb 12 '22 at 14:52