【问题标题】:EF Core with SQLite on Mono: e_sqlite3 not foundMono 上带有 SQLite 的 EF Core:找不到 e_sqlite3
【发布时间】:2019-05-27 16:58:45
【问题描述】:

我们将 Entity Framework Core 2.2.4 与面向 .NET Framework 4.7.2 的 SQLite 数据库一起使用。安装了以下 Nuget 包:

Microsoft.Data.Sqlite
Microsoft.EntityFrameworkCore.Sqlite
Microsoft.EntityFrameworkCore.Tools

在我的开发机器(Windows 10)上一切正常,但是当尝试在我们的 32 位 Linux 机器上使用 Mono 运行应用程序时,出现以下异常:

FATAL UNHANDLED EXCEPTION: 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: e_sqlite3
at (wrapper managed-to-native) 
SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods.sqlite3_libversion_number()
  at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number () [0x00000] in <61bb3ca1db9c41ea88f280f0b1600d58>:0
  at SQLitePCL.raw.SetProvider (SQLitePCL.ISQLite3Provider imp) [0x00008] in <3d4b21fb9c764efbb11f6e3b02efff52>:0
  at SQLitePCL.Batteries_V2.Init () [0x00005] in <f5d9c86a14864b5d99b8bdece1b8292c>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a89b9d7c1a66468eb33312af7ed3a74e>:0
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <a89b9d7c1a66468eb33312af7ed3a74e>:0
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <a89b9d7c1a66468eb33312af7ed3a74e>:0
  at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize () [0x0002f] in <b46e232ade014524baa458345f270c50>:0
  at Microsoft.Data.Sqlite.SqliteConnection..cctor () [0x00000] in <b46e232ade014524baa458345f270c50>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
  at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection () [0x00006] in <74192050a4d342039620dc7ef6678f71>:0
  at Microsoft.EntityFrameworkCore.Internal.LazyRef`1[T].get_Value () [0x00008] in <adf771f92e754fe1bb85c5850cd0c16b>:0
  at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection () [0x00000] in <69f795dffc844780bfcfff4ff8415a92>:0
  at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open (System.Boolean errorsExpected) [0x00000] in <69f795dffc844780bfcfff4ff8415a92>:0
  at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.Open (System.Boolean errorsExpected) [0x00000] in <74192050a4d342039620dc7ef6678f71>:0
  at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists () [0x0000c] in <74192050a4d342039620dc7ef6678f71>:0
  at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists () [0x0000b] in <69f795dffc844780bfcfff4ff8415a92>:0
  at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate (System.String targetMigration) [0x00012] in <69f795dffc844780bfcfff4ff8415a92>:0
  at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate (Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade) [0x00010] in <69f795dffc844780bfcfff4ff8415a92>:0
  at TestEfCorePlusSqlite.Program.Main (System.String[] args) [0x0000e] in <c4fad569c9a241ef887b5b2ddbc0225f>:0

由于应用程序是使用任何 CPU 配置构建的,因此在 bin/Debug 中创建 x86 和 x64 文件夹,两者都包含 e_sqlite3.dll。我已经尝试将 x86 dll 复制到 bin/Debug 但仍然出现错误。

到目前为止我已经尝试过:

  • 同时安装Microsoft.EntityFrameworkCore.Sqlite.Core SQLitePCLRaw.bundle_e_sqlite3 建议 here
  • 安装Microsoft.EntityFrameworkCore.Sqlite(或 Microsoft.Data.SqliteSQLitePCLRaw.bundle_green) 建议 here
  • SQLitePCLRaw.* 包的不同组合

我必须做些什么才能让 EF Core 和 SQlite 在 Mono 上运行?

【问题讨论】:

    标签: sqlite mono entity-framework-core


    【解决方案1】:

    在一个令人耳目一新的周末之后,我又重新审视了这个问题。我找到了关于DllNotFoundExceptionofficial Mono documentation 并使用MONO_LOG_LEVEL=debug mono YourApp.exe 找出Mono 试图加载的lib。这是/usr/lib/libe_sqlite3.so,在我的系统上不可用。我所做的只是复制可用的/usr/lib/libsqlite3.so 并将其重命名为libe_sqlite3.so。我不确定这是否是首选方式,但我的应用程序有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-01
      • 2021-04-21
      • 2019-12-22
      • 2019-06-21
      • 2020-11-27
      • 2016-08-22
      • 1970-01-01
      • 2018-07-09
      相关资源
      最近更新 更多