[.Net Framework 4.8]Library e_sqlite3 not found
See original GitHub issueA .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
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:51 (10 by maintainers)
Top Results From Across the Web
Microsoft.Data.SQLite: Library e_sqlite3 not found
Data.Sqlite is not compatible with the version of .Net Framework. You can try to change the version of NuGet of Microsoft.Data.Sqlite to 2.2....
Read more >Untitled
I am using Sqlite driver in Delphi XE2 for Firemonkey. Everything is ok for Win32 and OSX, ... Net Framework 4.8]Library e_sqlite3 not...
Read more >Untitled
Net Framework 4.8]Library e_sqlite3 not found #19396 - GitHub https://www.sqlite.org/forum/info/217f3b9e647d97c0 Using SQLite in a C# Application CodeGuru ...
Read more >Untitled
The sqlite core database was not found ... Net Framework 4.8]Library e_sqlite3 not found #19396 - Github https://www.bing.com/ck/a?!
Read more >Untitled
Net Framework 4.8]Library e_sqlite3 not found #19396 - GitHub WebJan 2, 2021 · Many of the database models have .HasColumnType("nvarchar(max)").
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
When Visual Studio is running the unit tests (xUnit), the net48 DLLs are copied to a
AppData\Local\Tempfolder and executed from there. The native DLLs are not copied. That leads to this error.I’ve created a hack to workaround the issue. It copies the
runtimesfolder from the Assembly.Location to Assembly.CodeBase folders. In my case, I only need this when running unit tests, so I’m fine with the ugliness of the hack. Ithttps://gist.github.com/FuncLun/fff2c63c7d37f4ff3d20f70e00bb241f
Another way to workaround this issue that doesn’t involve adding code in your test project is to disable xUnit test runner shadow copy. Here is how:
xunit.runner.jsonfile with the following contentHere’s how I did it on @MatthewKing’s sample code: https://github.com/0xced/Issue19396/commit/73d1504b2698b3db23309e40364b4e943fab315e
And once you know the solution, it becomes easier to find where it was already discussed. ¯_(ツ)_/¯