Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CorFlags.exe, System.Data.SQLite.dll and BadImageFormatException

Running CorFlags.exe against System.Data.SQLite.dll from http://sqlite.phxsoftware.com/ produces the following output.

Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 24
ILONLY    : 0
32BIT     : 0
Signed    : 1

As you can see, 32BIT is not specified and PE is equal to PE32. According to Moving from 32-bit to 64-bit application development on .NET Framework, this means that the assembly is Any CPU. However, using the assembly from a 64 bit application results in an error:

System.BadImageFormatException: Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'System.Data.SQLite'

If CorFlags.exe is reporting Any CPU, why does the exception occur? Is the assembly incorrectly marked with 32BIT: 0?

I know that there is a 64-bit version available too, I'm just want to know what is causing the error.

like image 462
Giorgi Avatar asked Dec 22 '22 18:12

Giorgi


2 Answers

The System.Data.SQLite.dll file you are using is a mixed-mode assembly, which means it is not a pure .NET code (see also the “ILONLY : 0” flag), it contains also unmanaged machine code, which cannot be “Any CPU”. So, as the DLL contains 32-bit native code, it can be loaded only into 32-bit process, otherwise a BadImageFormatException occurs.

like image 176
Mormegil Avatar answered Dec 24 '22 07:12

Mormegil


If you download the SQLite-1.0.66.0-binaries.zip file from sourceforget.net then this contains a bin/x64 directory with a System.Data.SQLite.dll file which is what you are looking for.

It also has an Itanium directory too..

The URL is:

http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/

like image 25
Stephen Gennard Avatar answered Dec 24 '22 08:12

Stephen Gennard