EF7 SQLite Click-Once Deployment Error

I'm working on a WPF client app with a SQLite database (view to build an iOS app with Xamarin in the future).

The Error

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:

Package folder

Now, if we look in our project target directory, we notice there is an x86 and x64 sub-directory with these DLLs in:

Target folder

Now, when we look in the deployed click-once application which will be in a directory like this:

C:\Users\geoff\AppData\Local\Apps\2.0\WPBJ2B04.BKA\PN5A1WW5.2WE\ques..tion_7b7f6e03bc292b23_0001.0000_24569b1cbc6fe91b

The x86 and x64 directories are missing, in fact the DLLs aren't even in the root.

Solution

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): DLL folders
  • We can see that these DLLs will be deployed before we publish, opening the project properties, then clicking Application Files on the Publish tab: App Files Now when we publish and run the app, the native DLLs are available and it launches fine.