efcore: Unable to load DLL 'e_sqlite3' on EF Core 2.0

I’m testing my code using sqlite in memory database and I get this error when trying to run a test.

System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception. ---> 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)

Further technical details

EF Core version: 2.0.0 Database Provider: Microsoft.EntityFrameworkCore.Sqlite Operating system: Visual Studio 2017

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 35 (13 by maintainers)

Most upvoted comments

Is everyone here using a separate class library for their DbContext? If so, the solution to the original issue is to add a reference to SQLitePCLRaw.bundle_green to the consuming app/test projects. This is just a known/by-design limitation of how NuGet handles transitive references.

@bricelam, @ajcvickers I am still facing this issue even after trying all the answers in this thread. Does this issue still persist in later builds ? I am also using Sqlite db for unit testing with specflow.

Technical Details: Microsoft.EntityFrameworkCore 2.2.4 Microsoft.Data.Sqlite.Core 2.2.4

Solution (at least for raspberry Pi) is following:

  • find winsqlite3.dll (It is located in WINDOWS/System32) on Raspberry Pi
  • copy this dll into publish destination for .net core project
  • rename it to: e_sqlite3.dll Start dotnet console application. This works both for console as well as for Asp.Net MVC core application.

This is still an issue.

@bricelam After follow up with https://github.com/ericsink/SQLitePCL.raw/issues/175 the solution is to use

dotnet remove package Microsoft.EntityFrameworkCore.Sqlite
dotnet add package Microsoft.EntityFrameworkCore.Sqlite.Core
dotnet add package SQLitePCLRaw.bundle_e_sqlite3
dotnet publish -r win10-arm

dotnet publish -r win10-arm

The build instructions on https://github.com/dotnet/core/blob/master/samples/RaspberryPiInstructions.md are missleading.

@bricelam “Is everyone here using a separate class library for their DbContext? If so, the solution to the original issue is to add a reference to SQLitePCLRaw.bundle_green to the consuming app/test projects. This is just a known/by-design limitation of how NuGet handles transitive references.”

Yes, I am trying to do just that… is there any way of bypassing this limitation? I want to deliver the customer just one DLL containing the database layer… don’t want him to have to download extra references.

Yeah, I’m not sure why NuGet doesn’t just treat win-x* and win7-x* as aliases during publish…

(and win-arm and win8-arm)

Ah, you need to use win7-x86 at least. SQLitePCL.raw doesn’t include a dll for win-x86.

Still having this error in Windows 10, in spite adding <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.0" /> as suggested. Weird thing, I had no such error in macOS (probably due to sqlite being part of the system)

@bdominguez This looks like an issue with transitive packages in project references in NuGet. Adding the following to Test.csproj makes it work.

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.0" />

Can you file a new issue on NuGet/Home?

@bdominguez What framework and runtime are you using?

@glegleme According to ericsink/SQLitePCL.raw#161 this should work. You could also try just using the version that ships with Windows 10:

dotnet remove package Microsoft.EntityFrameworkCore.Sqlite
dotnet add package Microsoft.EntityFrameworkCore.Sqlite.Core
dotnet add package SQLitePCLRaw.bundle_winsqlite3