SQLite error when publishing .NET Core 2 Console App

0

I'm having issues publishing a .NET Core console app. It works fine when I run it from Visual Studio and I'm getting zero errors. However, when I publish it with: dotnet publish -c release -r win-x64 --self-contained

I'm getting an error about SQLite. I'm using the Microsoft.EntityFrameworkCore.Sqlite library. The error I'm getting is:

System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->

System.DllNotFoundException:
Unable to load DLL 'e_sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I don't know what could be causing the issue and every single thing I find on the internet either doesn't work or doesn't apply to my situation. I really don't know what I'm doing wrong and I've tried just about everything.

c#
.net
visual-studio
sqlite
asked on Stack Overflow Feb 5, 2018 by Aevan • edited Feb 5, 2018 by Aevan

2 Answers

0

If you're using the System.Data.SQLite library then this exception is mentioned in their FAQ:

https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q5

Why do I get a DllNotFoundException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run my application?

Either the named dynamic link library (DLL) cannot be located or it cannot be loaded due to missing dependencies. Make sure the named dynamic link library is located in the application directory or a directory along the system PATH and try again. Also, be sure the necessary Visual C++ runtime redistributable has been installed unless you are using a dynamic link library that was built statically linked to it.

So:

  1. Ensure you have the latest Visual C++ runtime installed: https://support.microsoft.com/kb/2019667
  2. Ensure sqlite3.dll is in the same directory as the rest of your DLLs
  3. Unrelated to your current issue, but ensure the build of your sqlite3.dll matches the ISA of your web-server process (i.e. ARM, x86, x64).
  4. Ensure your web-application's host webserver process isn't being started with unusual environment variables, PATH or working-directory.
answered on Stack Overflow Feb 5, 2018 by Dai
0

The SQLite EF Core provider is technically a 3rd-party library, from the point of view of the .NET Core. You need to make sure that the dependencies are fixed up for your project, according to this.

Basically, you need to make sure the dependency NuGet package is called out in your .csproj file as a dependency, like so:

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="[version #]" />
</ItemGroup>

And you need to make sure the NuGet package is installed on your system, since the dependency is resolved from the local NuGet cache when the project is published.

answered on Stack Overflow Feb 6, 2018 by Mark Benningfield

User contributions licensed under CC BY-SA 3.0