Search code examples
c#winformsuwpsystem.data.sqlitewindows-application-packaging

Winform App to UWP App System.Data.SQLite error


Error Message

Hi everyone. Hoping someone can help me and thank you to anyone that tries.

I have a WinForm app that I'm using in a Windows Application Packaging Project (Creates MSIX packages for distribution in Microsoft Store). WinForm app is in C# using .NET 4.6 and compiles without errors, runs as expected. When I run the UWP package, it installs but I get an error when I run it referring to System.Data.SQLite and I'm not sure why. In both projects (WinForm App and UWP package) I have it set to Any CPU, but I think there is a 32/64 bit problem. Has anyone had this problem before and how can I fix it? Full Error message:

The error details are as follows:

See the end of this message for details on invoking

just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op)

at System.Data.SQLite.SQLite3.StaticIsInitialized()

at System.Data.SQLite.SQLiteLog.PrivateInitialize(String className)

at System.Data.SQLite.SQLiteLog.Initialize(String className)

at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)

at System.Data.SQLite.SQLiteConnection..ctor(String connectionString)

at MyApp.FRMGetMyFunction.CMDGetMyFunction_Click(Object sender, EventArgs e)

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************

mscorlib

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B

CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll


MyApp

Assembly Version: 1.0.0.0

Win32 Version: 1.1.44.0

CodeBase: file:///C:/Program%20Files/WindowsApps/58250MyCompany.FWMyAppPro_1.1.44.0_neutral__f0fg3kf9fk41a/MyApp/MyApp.exe


System.Windows.Forms

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9251.0 built by: NET481REL1LAST_C

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll


System

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9261.0 built by: NET481REL1LAST_C

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll


System.Drawing

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9037.0 built by: NET481REL1

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll


System.Configuration

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9037.0 built by: NET481REL1

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll


System.Core

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll


System.Xml

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9037.0 built by: NET481REL1

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll


Accessibility

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9037.0 built by: NET481REL1

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll


System.Data.SQLite

Assembly Version: 1.0.119.0

Win32 Version: 1.0.119.0

CodeBase: file:///C:/Program%20Files/WindowsApps/58250MyCompany.FWMyAppPro_1.1.44.0_neutral__f0fg3kf9fk41a/MyApp/System.Data.SQLite.DLL


System.Data

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9214.0 built by: NET481REL1LAST_B

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll


System.Transactions

Assembly Version: 4.0.0.0

Win32 Version: 4.8.9037.0 built by: NET481REL1

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll


************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.

For example:

<system.windows.forms jitDebugging="true" />

When JIT debugging is enabled, any unhandled exception

will be sent to the JIT debugger registered on the computer

rather than be handled by this dialog box.

Edit: Updated the project as you suggested, but I'm still getting the same error. I have cleaned both projects and rebuilt each. enter image description here


Solution

  • Worked out the issue. Included a reference to a 32 bit SQLite.Interop.dll. Also, SQLite.Interop.dll was wasn't getting added in the build. Added x64 and x86 folders in teh base of my project. Included x64\SQLite.Interop.dll and x86\SQLite.Interop.dll in my project and setting to always copy for both DLLs fixed the issue. Hope that helps anyone that comes across the same issue. Thanks you everyone for your help and suggestions.