5

I am able to build and execute on my development box my Winforms applicaiton, however I run into this error, when I attempt to run my application on another clean box (a VM).

Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.DllNotFoundException
   at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(System.Data.SQLite.SQLiteConfigOpsEnum)
   at System.Data.SQLite.SQLite3.StaticIsInitialized()
   at System.Data.SQLite.SQLiteLog.Initialize()
   at System.Data.SQLite.SQLiteConnection..ctor(System.String, Boolean)
   at System.Data.SQLite.SQLiteConnection..ctor()
   at DittoSql.SQL..ctor()
   at MyApp.Program..cctor()

Exception Info: System.TypeInitializationException
   at MyApp.Program.Main(System.String[])

I used Nuget to add SQLite to my project.

SQLite added to project using NuGet

Sadly, the event viewer log does not provide what DLL that the system cannot find. I did research and the one thing that turned up is .Net compatibility. I was at 4.6.2, which on SQLite v1.08 does not support, so I downgraded to .Net 4.6, which is listed.

Both machines run Windows 10 X64 with all the latest updates.

Here is a screenshot of the app folder showing the files.

Application folder showing SQLite files

UPDATE

Based on the comment from @Plutonix, here is a screenshot showing the references to my project. Missing is System.Data.SQLite.Core, which contains the interop files. There are different versions for each .Net version and OS type, so I cannot just browse for the folder inside the packages folder, besides that is a terrible hack. There should be a clean way to add the reference.

Project references missing System.Data.SQLite.Core

For the record, I briefly thought of that file, but I did not see it or the core and figured version 1.08 does not use it, but I guess that it does.

NOTE: I copied the SQLite.Interop.dll file manually to the VM and the project loaded. Procman was not that helpful, too much information perhaps, though I filtered out everything but my app. Anyways, the problem is how to get a reference to the SQLite core.

UPDATE 2

Uninstalling all sqlite components from NuGet and then reinstalling SQLite does not add reference the core in the project, annoyingly.

UPDATE 3

This SO article (in the answer) states the problem. Basically, NuGet for whatever messed up reason correctly "requires" the core, but then does nothing with it. As such, NuGet does not distribute a required file. I saw the answer to "copy" the X86/X64 folders, etc.

I, for one, name that as a serious defect/bug in the NuGet SQLite package. Yes, this question becomes sort of a duplicate of the referenced question, if you know the answer, but I did not, so it is not. I never received any error message on the interop DLL.

Sarah Weinberger
  • 15,041
  • 25
  • 83
  • 130
  • 3
    sysinternals procmon will show you what files a process is trying to find – pm100 Jul 26 '18 at 20:25
  • 2
    Looks like you are missing `SQLite.Interop.dll` – Ňɏssa Pøngjǣrdenlarp Jul 26 '18 at 20:30
  • @Plutonix An article that I looked at said to add System.Data.SQLite.Core as a reference to the project to get the interop. I do see the interop file inside the Core packages folder, different versions for OS types, but missing is the how to get Nuget to add that to my project. – Sarah Weinberger Jul 26 '18 at 20:49
  • @Plutonix Yes, adding the file manually resolved the issue, so now the question is why the Core did not add in the first place and how to get the core to add. – Sarah Weinberger Jul 26 '18 at 20:59
  • @ŇɏssaPøngjǣrdenlarp your comment saved my day. Thanks. – ahmed abdelqader Mar 29 '20 at 19:52
  • `SQLite.Interop.dll` requires the VC++ redistributable package for the VS version with which it was compiled. Better to just download the right SQLite C# package from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki – rustyx Dec 14 '20 at 12:46

1 Answers1

0

(I want someone to come up with a better answer, as mine is a hack.)

Until a real elegant and proper solution comes along, I thought of this workaround. Add the following to the Post-build event command line" onBuild Events` tab of the project settings.

Anyone using my command line would obviously have to set net46 to the .Net version used in the project and set the SQLite version, here 1.0.108.0 to whatever the version will be.

robocopy "$(ProjectDir)\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\$(PlatformName)" $(TargetDir) SQLite.Interop.dll

Here is a screenshot.

Post Build Events Showing robocopy

NOTE

I also thought of conditional logic to the project file that would include a DLL, but that was more complicated than a simple RoboCopy.

Sarah Weinberger
  • 15,041
  • 25
  • 83
  • 130