Bad Image Exception while loading SQLite DLL - c#

I have a project that is build on Any CPU configuration, .Net Framework 2.0, vs2008 with 32bit version of SQLite dll used in it.
Well this works fine on my 32 processor environment, but when i ran this project on 64bit processor environment i experienced
"Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture-neutral,
PublicKeyToken=db937bc2d44ff139' or one of its dependencies.
An attempt was made to load a program with an incorrect format."
I even tried adding 64 bit dll on my project but it did not work.
I have tried all the solutions but that did not work for me. Since i am bound to build the project on 32 bit machine, i need a way to run this tool on my 64 bit environment too.
Any suggestions/comments/improvements means a lot for me.
Thanks in Advance.

Compile your application using x86 configuration.
When dealing with dlls like SQLLite that are compiled for x86, your process must be running in x86 mode.

I find these steps can be used to deal with sqlite.
Download NuGet
open cmd and type nuget install System.Data.Sqlite -- note it will create a folder in your current directory
copy dlls from net20 folders to your solution like so.
Add a reference to System.Data.SQLite.dll
Make sure you copy both SQLite.Interop.dlls to your output dir
Hope it helps.

Related

Sqlite Unable to load DLL 'SQLite.Interop.dll' when set to x86, Could not find type 'xxx' when set to x64?

Trying to use Sqlite in my VB.net app, thought it would be simple so I installed it via the NuGet package manager. Now i've lost a week to this hate to admit, I just can't make it work for the life of me.
When I set my build to x86, it say's it can't load SQLite.Interop.dll, when I set my build to x64 it can't find one of my custom controls within my project. I tried some solutions from other SO questions but none of them worked for me.
Can someone help me out here? It's getting pretty frustrating. Apparently their NuGet package is completely broken for me, so I downloaded just System.Data.SQLite.dll from the vendors website, referenced it in my project, set to Copy Always, and changed my build from AnyCPU to x86 (to match the DLL). Which results in an exception stating the referenced assembly cannot be found.
you also need to download the SQLite package from here http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
make sure you download abd install the x86 version even if your running x64.

Different version of assembly loaded from GAC

I have a typical problem of loading a dll from GAC. My application references a dll called MyAssembly.dll. Its assembly version is 1.1.6 and file version is 1.2.100 and it is added it to the GAC.
After a bug fix I updated the file version to 1.2.110 (but the same assembly version as there were no changes in the binary) and deployed to the GAC and the application works fine. But for some reason when i installed the previous build (Wise Installation, obfuscated dll), my application stopped working. It gives a Missing Method Exception. if I install the build 1.2.110 (Wise installation, obfuscated dll) my application works fine.
I am not sure why this strange behavior. When installing the lower version (1.2.100) on a machine where 1.2.110 is present, the dlls in the GAC are not overwritten. But when I load the dll and reads its AssemblyFileVersion attribute it says 1.2.100. But FileVersionInfo.GetVersionInfo gives me 1.2.110.
Could anyone help me with solving this issue, please?
The issue was solved by installing the assembly using ngen.exe utility.

ILNumerics mkl_custom dll not found

We have two applications that use ILNumerics and have run into the same issue with both. We use the mkl_custom.dll and during development the application runs fine. The dll in use during development sits in the bin32 folder automatically generated when downloading the ILNumerics from nuget. However when we install the applications we get "Unable to load DLL 'mkl_custom': The specified module could not be found. (Exception from HResult: 0x8007007E".
Here is what we have tried:
Building the application in Any CPU, x86.
Switching the bin32 to include the bin64 dll's and viсе-versa.
Running dependency walker and including all dll's that are needed.
Changing path variable.
We are using ILNumerics 3.3.3.0.
One of the dependencies for mkl_custom is msvcr*.dll. Packing this dll manually may work on some operating systems but not all. Make sure the target system has c++ runtime redistributable package installed.
This installs the msvcr dll correctly. Hopefully this should fix the issue

Loading an Assembly fails because of incorrect format

I develop on a pretty big windows forms .net (C#) application with several assemblys. Originally each assembly was build for the Target Platfom "Any CPU".
Due to a problem with Crystal Reports on x64 machines we had to build the whole project for x86 target platform. I startet rebuilding some of our Projects for x86 and it worked just fine.
But with one I have the problem that when I try to use it as a reference in another Assembly, the other one won't load it giving following Error:
Could not load file or assembly #MyAssembly# or one of its dependencies. An attempt was made to load a program with an incorrect format.
When playing Around with Crystal in a sample project with more than one assembly I found out that this error occurs when the Projects are build for different target platforms. But this isn't the case here. I build every Project for X86 and just can't figure out where the problem is here.
You can try, to build your MainProject (Executable) with target platform "x86" or "x64", an all other projects you set to "Any CPU".

ClickOnce installing old assemblies from cache

I'm using ClickOnce for installing my application written in C#. Everything worked fine till the last update after which start of my application ends with an error saying:
Could not load file or assembly MyAssembly... HRESULT: 0x80131040.
After some research I've found that there is an old version of MyAssembly located in my application's ClickOnce cache folder (C:\Documents and Settings..\Apps\2.0...). However there is an actual version in the deployment package.
I've also found this old version of MyAssembly in a standalone directory in the ClickOnce cache named after this assembly (plus some characters added).
It seems to me that for some reason ClickOnce used this old version of MyAssembly from the cache instead of the new version from the deployment package.
Uninstall/install of my application won't help.
How is this possible?
I have had the same behaviour. It mentioned the problem in another question. Since then, it has happened several times for us with different applications. One strange thing is that it behaves differently on different computers. So one computer could have been updated with the new assembly while another got the old one copied.
.NET ClickOnce deployment and wrong assemblies called after updated version
This appears to be a bug in .NET framework 3.5 SP1.
See Microsoft KB 971052.
Make sure this old assembly is loaded. You can use DllProfiler for that.

Categories