0
votes

I'm trying to program with SQLite on WinRT 8.1 on Visual Studio 2013. I installed SQLite with the WinRT 8.1 VSIX and the same one for Windows Phone 8.1 and also load the sqlite-net from nuget.

I use to get the following Error:

An exception of type 'System.BadImageFormatException' occurred in TimeTableAPP.Windows.exe but was not handled in user code

enter image description here

from this two lines of code:

SQLiteAsyncConnection cneu = new SQLiteAsyncConnection("newDB.db");
await cneu.CreateTableAsync<TestTable>();

same with

var conn = new SQLiteAsyncConnection(System.IO.Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "newDB.db"));
await cneu.CreateTableAsync<TestTable>();

with TestTable

[Table("TestTable")]
public class TestTable
{
    [PrimaryKey, AutoIncrement]
    public long Id { get; set; }
    public string nomnomnom { get; set; }
}

This issue seems to happen quite often and usually is solved by setting platform target to x86. As you can see I do so:

enter image description here

I have no idea what to try anymore. I ran a repair on the VC2013 installation, uninstalled and reinstalled the VSIX and made a project for shared Windows 8.1 and Windows Phone 8.1, with Windows Phone NOT triggering the error, but Windows Store App triggering the error with the same code.

1
I'm not used to nuget, when I copy-paste the command, it gives me a successful return: Installing 'System.Data.SQLite 1.0.93.0'. Successfully installed 'System.Data.SQLite 1.0.93.0'. Adding 'System.Data.SQLite 1.0.93.0' to App2. Successfully added 'System.Data.SQLite 1.0.93.0' to App2. But I cannot add using System.Data.SQLite, nor using SQLite like before - user3079834

1 Answers

1
votes

According to MSDN, this error occurs due to the formatting of a library or program being bad (usually mistmatched) - this can occur if your target is x86, but it can also occur if your target is explcitly x64 or there's a mismatch beyond your own code. Simply setting to x86 is not going to fix it if your program isn't x86. Make sure you try x64 and Any CPU, and check any available documentation on what SQLite says it's running under.

Also don't forget you can try to install the libraries directly instead of from NuGet, as there may be some conflict in the libraries themselves. outside of your control.