Visual Studio C# - SQLite.Interop.dll not found

7

I am currently trying to create with Visual Studio a C# application working with SQLite. I installed SQLite for my program with NuGet and three references appeared in the Solution Explorer (System.Data.SQLite, System.Data.SQLite.EF6, System.Data.SQLite.Linq).

When I execute my app in VS, everything works fine. However, whenever I publish it (with ClickOnce) and try to run the app, it crashes with the following error : System.DllNotFoundException : Unable to load DLL 'SQLite.Interop.dll' : the specified module cannot be found (Exception from HRESULT : 0x8007007E)

After some research, I found this dll in the Debug folder and copied it in the folder where the ".exe" version of my program is created (after publishing and executing "setup.exe"). This way, the app runs well.

But I'm not really satisfied with this solution, since it seems really dirty. I don't want future users to have to do this manually when they install my app !

Therefore, my question is : What can I do to make sure that this dll is installed together with my program ?

Note : I tried the first answer of this post : unable to load dll sqlite interop dll WPF But I didn't seem to work for me.

c#
sqlite
dll
visual-studio-2015
asked on Stack Overflow Jul 26, 2016 by Daneel • edited Sep 11, 2020 by ΩmegaMan

9 Answers

11

I also encountered the similar issue in my environment of Visual Studio 2017 and NET Framework 4.5, the circumstance is:

I am developing an Outlook Add Ins using ClickOnce to publish it and SQLite as the database. After having installed the SQLite library into the project from NuGet, it works perfectly in the local environment but pops up the exception error message "Unable to load DLL 'SQLite.Interop.dll'" on the client machine.

I compared the two environments and found the DLL file 'SQLite.Interop.dll' had not been published to the client machine that we can see in the following graphic. enter image description here

I searched 'SQLite.Interop.dll' in local environment and found it is saved in the following folder "{project}\packages\System.Data.SQLite.Core.1.0.105.2\build\" for the specific .Net FrameWork enter image description here

So, my solution is adding these two DLL libraries into the project, then they can be published to the client machine using the ClickOnce. enter image description here

(Notice: The selected DLL version should be as same as the NET Framework version in your environment.)

answered on Stack Overflow Aug 3, 2017 by ukalpa
10

See Using Native Library Pre-Loading at https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

You likely need to include the x86 and x64 folders under the the other SQLite DLL.

Edit: I've added the relevant info below in case the above link ever dies/changes.

If the development and customer machines may have different processor architectures, more than one binary package may be required. For this situation, using the native library pre-loading feature is highly recommended. It is available as of version 1.0.80.0 and enabled by default. In order to take advantage of this feature, the separate managed and interop assemblies must be used with XCOPY deployment (i.e. this feature is not supported by the mixed-mode assembly, nor when the assembly is deployed to the global assembly cache), resulting in an application deployment that looks something like this:

  • bin\App.exe (optional, managed-only application executable assembly)
  • bin\App.dll (optional, managed-only application library assembly)
  • bin\System.Data.SQLite.dll (required, managed-only core assembly)
  • bin\System.Data.SQLite.Linq.dll (optional, managed-only LINQ assembly)
  • bin\System.Data.SQLite.EF6.dll (optional, managed-only EF6 assembly)
  • bin\x86\SQLite.Interop.dll (required, x86 native interop assembly)
  • bin\x64\SQLite.Interop.dll (required, x64 native interop assembly)

The string "bin" above represents the directory where the application binaries are to be deployed on the target machine. With the native library pre-loading feature enabled and the application deployment shown above, the System.Data.SQLite managed-only assembly will attempt to automatically detect the processor architecture of the current process and pre-load the appropriate native library.

answered on Stack Overflow Jul 26, 2016 by topshot • edited May 13, 2019 by topshot
7

By default the dll sqlite.interop.dll does not come with NuGet installation of SQLite. To solve this you need to add both the dlls, x86 and x64. At the SQLite website download the pack containing necessary dlls. Install them in client or copy these dlls to your Project before distributing.

answered on Stack Overflow Jan 17, 2017 by Rafael • edited May 5, 2017 by Matt G
6

Please use the answer to the duplicate issue: https://stackoverflow.com/a/60176344/3634867

Don't store the dll yourself and copy it to /bin manually, it will lost control to the version updating and depenedcy.

TL;DR;

for old csproj file:

<PropertyGroup> 
    <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
    <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
    <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
    <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>

for new csporj file: (i.e. projects beginning with <Project Sdk="Microsoft.NET.Sdk.*">)

<PackageReference Include="System.Data.SQLite.Core" Version="1.0.110" PrivateAssets="none"/>
answered on Stack Overflow Jul 8, 2020 by John_J
1

If it is an installable file. i.e, if u are creating setup file, then you have to add the dll manually to the primary output file.

Go to properties of the setup project and in configuration settings, select pre-requisites SQLLite, select(Checkbox) install it from the project location.

See if this solves your issue.

answered on Stack Overflow Jul 26, 2016 by Prabhanjan_13
1

"Note : I tried the first answer of this post : unable to load dll sqlite interop dll WPF But I didn't seem to work for me."

I tried that, too, and finally got it working. However, important is:

  1. Insert the sqlite.interop.dll as an existing item to the root of the project you are going to build.
  2. In the properties of that file, make sure its build processing is 'content' (not embedded resource as suggested) and, of course, copied to the output directory always.

Hope that helps to beat that annoying bug.

answered on Stack Overflow Jan 5, 2017 by mitch182
1

The System.Data.SQLite nuget package includes a Build folder with a targets file that will copy these interop dlls. To solve this, we had to tell the project we were packaging into our own nuget, to NOT exclude this build target/folder.

Our project (the one we package and then use elsewhere) needed to have PrivateAssets="None" or PrivateAssets="Analyzers" if you want to make sure not to include Analyzers.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <RootNamespace>MyNamespace</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ServiceStack.OrmLite.Sqlite.Core" Version="5.6.0" />
    <PackageReference Include="System.Data.SQLite.Core" Version="1.0.111"  PrivateAssets="Analyzers" />
   </ItemGroup>

</Project>
answered on Stack Overflow Oct 4, 2019 by Beau Gosse
1

SQlite.Interop is not referenceable, you have to:

  1. In your VS project Add Existing File: Sqlite.Interop.dll actual location is .\bin\Debug\x86 or \bin\Debug\x64

  2. Select properties and set Compilation Action in "Content" and copy to the output directory = "Always Copy"

  3. Rebuild

answered on Stack Overflow Oct 17, 2019 by Xtian11
1

Upgrading the System.Data.SQLite.Core Nuget package to version 1.0.109.2 fixed the error for me.

answered on Stack Overflow Dec 8, 2020 by Amara Miloudi

User contributions licensed under CC BY-SA 3.0