System.BadImageFormatException on running ServiceStack examples.

TheVillageIdiot picture TheVillageIdiot · Jan 11, 2011 · Viewed 9k times · Source

I am trying to run ServiceStack Examples projects. When I run the web client I am getting the following error:

{System.BadImageFormatException: An attempt was made to load a program with an 
    incorrect format. (Exception from HRESULT: 0x8007000B)
    at Mono.Data.Sqlite.UnsafeNativeMethods.sqlite3_open_v2(Byte[] utf8Filename, 
    IntPtr& db, Int32 flags, IntPtr vfs)
    at Mono.Data.Sqlite.SQLite3.Open(String strFilename, SQLiteOpenFlagsEnum 
    flags, Int32 maxPoolSize, Boolean usePool)
    at Mono.Data.Sqlite.SqliteConnection.Open()
    at ServiceStack.OrmLite.OrmLiteConnection.Open()
    at ServiceStack.OrmLite.OrmLiteConnectionFactory.OpenDbConnection()
    at ServiceStack.Examples.ServiceInterface.Support.ConfigureDatabase
         .Init(IDbConnectionFactory connectionFactory) 
    in E:\ServiceStack.Examples\src\ServiceStack.Examples\
    ServiceStack.Examples.ServiceInterface\Support\ConfigureDatabase.cs:line 23}

I have downloaded latest System.Data.SQLite.dll file and tried to use it, but am getting still the same error. I am running 64-bit VS2010 on Windows 7 64-bit box.

Answer

Dirk Vollmar picture Dirk Vollmar · Jan 11, 2011

Set the platform target of your main project to x86 to fix this. This can be done under Project... -> Properties -> Build.

SqlLite is most likely a 32-bit components, and to be able to load it your application needs to be a 32-bit application as well (64-bit processes cannot load 32-bit components and vice versa).