profile
viewpoint

Ask questions[.Net Framework 4.8]Library e_sqlite3 not found

A .Net Framework 4.8 program referencing a .Net Standard 2.0 using EFCore.Sqlite 3.1 can't simply run (on Any CPU/X64/X86) with an exception shown:

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.Exception: Library e_sqlite3 not found

   at SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
   at SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
   at SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
   at Microsoft.Data.Sqlite.SqliteConnection..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Test.Program.Main(String[] args) in E:\Edit\CS\WPF\Memo\Test\Program.cs:line 22

But the output folder does contain e_sqlite3.dll, which seems to be a bug.

To Reproduce

				var connection = "DataSource=default.db";
				var builder = new DbContextOptionsBuilder<Db>();
				builder.UseSqlite(connection);
				builder.EnableSensitiveDataLogging();
				var options = builder.Options;
				using (var db = new Db(options))
				{
					db.Database.Migrate(); //this line throws that exception
				}
dotnet/efcore

Answer questions ericsink

I understand.

The recent changes in 2.0.5 prerelease builds are related to

ericsink/SQLitePCL.raw#389

and

ericsink/SQLitePCL.raw#419

When I made the code changes related to those issues, I worried that there would be cases that I broke. Your situation appears to be one such case.

I'll try to find a fix that addresses the concerns without causing breakage.

useful!

Related questions

5.0 RC1 logs query splitting warnings for queries using AutoMapper ProjectTo hot 40
A host error has occurred during startup operation (5.0.0-preview.4.20220.10 and 5.0.0-preview.5.20278.2) hot 35
EF Migration Error : Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions hot 31
Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0 - efcore hot 29
"Enumerator failed to MoveNextAsync" when using SingleOrDefaultAsync - after Save hot 16
EF core 3 query LastOrDefault on entity with OwnsOne cannot translate expression hot 14
MissingMethodException: Method not found: &#39;Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences - efcore hot 12
Can't build for netcoreapp3.1 - Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.7.0.0' hot 12
The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects hot 11
What's the recommended way to .Join() using Keyless types in EF5? hot 10
[BUG] A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. hot 10
Unable to create migrations without Microsoft.EntityFrameworkCore.Design in ASP.NET Core Web layer. hot 10
Cannot create a DbSet for 'Model' because this type is not included in the model for the context. hot 9
DbSet<T>.OfType<TDerived>() does not work hot 9
Eager loading of polymorphic Many-To-Many property throws exception - efcore hot 8
source:https://uonfu.com/
Github User Rank List