I'm working on a WPF client app with a SQLite database (view to build an iOS app with Xamarin in the future).
The application works fine locally, but when I publish and create a Click-Once deployment, the application was not launching and I was getting this error in the Windows EventViewer:
Application: My.App.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.DllNotFoundException at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(IntPtr, Microsoft.Data.Sqlite.Interop.Sqlite3Handle ByRef, Int32, IntPtr) at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2...
This means that the interop DLLs can't find the native SQLite DLLs, so can't run.
I've installed EntityFramework.Sqlite NuGet packages which has Microsoft.Data.Sqlite as a pre-requisite containing the SQLite interop. If we take a look in the packages folder, we can see the native DLLs live under the runtimes folder:
Now, if we look in our project target directory, we notice there is an x86 and x64 sub-directory with these DLLs in:
Now, when we look in the deployed click-once application which will be in a directory like this:
The x86 and x64 directories are missing, in fact the DLLs aren't even in the root.
The solution is simple. We just need to deploy the x86 and x64 directories with the other published binaries. To do this we do the following:
- Add an x86 and an x64 folder to the visual studio project
- Link the native binaries from the package folder (you could add them if you wanted):
- We can see that these DLLs will be deployed before we publish, opening the project properties, then clicking Application Files on the Publish tab: Now when we publish and run the app, the native DLLs are available and it launches fine.