Periodically I am getting the following exception:
Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I am using 1.0.82.0. version, installing it with nuget in VS2010, OS Win7 64.
Once exception starts to appear, it appears constantly - in debug and release and running application within or outside VS.
The only way to stop it is logoff and logon. The exception is not thrown and dll is loaded. It can work for days, but then it can break again.
Has anyone seen something like this and is there a solution for it?
Also added the dll to the test project (through Nuget Manager) and it fixed it.
Copy SQLite.Interop.dll in project directory.
I had this same problem when using SQLite in a WPF project whose platform target was
Any CPU
. I fixed it by following the following steps:prefer 32-bit
option.Alternatively, you could just set the platform target to
x86
orx64
. I think this problem is caused by theSystem.Data.SQLite
library using the platform target to get the location of the 'SQLite.Interop.dll' file.UPDATE:
In case the project designer cannot be reached, just open the project (
*.csproj
) file from a text editor and add the value<Prefer32Bit>false</Prefer32Bit>
into the<PropertyGroup>...</PropertyGroup>
tag.Example code
You could also get this error if you are trying to run a 32 bit dll, in a 64 bit project.
I got this when I have placed the same file(SQLite.Interop.dll in 32 bit version) in both the x86 and x64 folder.
I am working on a simple console application to add some test data to an SQLite database and was getting this error. The configuration for the project is "Any CPU". I fixed it by copying the SQLite.Interop.dll to the bin\debug folder. A better way would be to use the method by @Wil, but how do you specify this for "Any CPU" configuration?
I have started using Costura.Fody to package (.net) assemblies and embed and preload native dlls. This also helps later, with distribution as you can send one file.
Install Costura Fody from Nuget.
In your C# project create a folder called costrua32. In there add any native dlls you which C# to load.
Once you have added them to this folder. Click on the properties window and change build action to "Embedded Resource"
Finally you need to amend the XML file called FodyWeavers.xml as follows. Here I am specifying load the sql dll first. (note you drop the .dll)
The advantage of this is that you do not have to write any pre or post build events, and the end product is totally encapsulated in to one larger file.