dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.52k stars 3.13k forks source link

Unable to load shared library 'e_sqlite3' exception with net6 rc1 and efcore Microsoft.EntityFrameworkCore.Sqlite.Core 6.0.0-rc.1.21452.1 #26163

Closed richardjharding closed 1 year ago

richardjharding commented 2 years ago

I'm struggling to get ef core 6.0.0-rc.1.21452.1 and the rc1 net core 6.0 working with sqlite I'm running the code inside a docker container mcr.microsoft.com/dotnet/sdk:6.0.100-rc.1-focal

I'm attempting to run some tests against code that normally uses efcore against SQL server but in the tests I've been using sqlite in memory database - this was all working with the v5 versions of netcore and ef etc

I have the following package refs:

<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0-rc.1.21452.15" />
    <PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.0-rc.1.21452.10" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
    <PackageReference Include="Moq" Version="4.16.1" />
    <PackageReference Include="NUnit" Version="3.13.1" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
    <PackageReference Include="coverlet.collector" Version="3.0.2" />
    <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.6" />
    <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.0.6" />
    <PackageReference Include="SQLitePCLRaw.core" Version="2.0.6" />
    <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="2.0.6" />
    <PackageReference Include="SQLitePCLRaw.lib.e_sqlite3.linux" Version="1.1.14" />

(I've tried many combinations of the above packages)

And I get the following exception logs

--TargetInvocationException
#18 5.754    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
#18 5.754    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
#18 5.754    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
#18 5.754    at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
#18 5.754    at Microsoft.Data.Sqlite.SqliteConnection..cctor()
#18 5.754 --DllNotFoundException
#18 5.754    at System.Runtime.InteropServices.NativeLibrary.LoadByName(String libraryName, QCallAssembly callingAssembly, Boolean hasDllImportSearchPathFlag, UInt32 dllImportSearchPathFlag, Boolean throwOnError)
#18 5.754    at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError)
#18 5.754    at System.Runtime.InteropServices.NativeLibrary.Load(String libraryName, Assembly assembly, Nullable`1 searchPath)
#18 5.754    at SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
#18 5.754    at SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
#18 5.754    at SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
#18 5.754    at SQLitePCL.Batteries_V2.Init()
#18 5.754   Failed HandlerReturnsPipelineWhenSubIsMatch [< 1 ms]
#18 5.754   Error Message:
#18 5.754    System.TypeInitializationException : The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
#18 5.754   ----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
#18 5.754   ----> System.DllNotFoundException : Unable to load shared library 'e_sqlite3' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libe_sqlite3: cannot open shared object file: No such file or directory
#18 5.754   Stack Trace:
#18 5.754      at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)

Is this a known issue or am I missing some prereqs in the docker container - I've added the following to my dockerfile

RUN apt-get update
RUN apt-get install -y nodejs yarn sqlite3

but otherwise its the stock SDK image

The same project works as expected on windows 10

ajcvickers commented 2 years ago

@richardjharding Make sure you have updated to the latest package versions where possible. For example, Microsoft.Data.Sqlite 2.0.1 is very old.

richardjharding commented 2 years ago

yep - not spotted that, updated to latest 6.0.0-rc.1.21452.10 but get the same error with that image

ajcvickers commented 2 years ago

/cc @bricelam

bricelam commented 2 years ago

Those package references still seem problematic. You're mixing two versions of SQLitePCLRaw (2.0.6 and 1.1.14), and you have two bundles installed (e_sqlite3 and green).

ajcvickers commented 2 years ago

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.