我的ASP.NET MVC (.Net Framework4.7.2) web应用程序使用Microsoft.Data.Sqlite 5.0.2崩溃(包括调试IIS,以及Windows10中本地IIS4.7.2中的app.publish ):
SqliteConnection dbConn = new SqliteConnection("Data Source=test.db");
引发的异常:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
Source=Microsoft.Data.Sqlite
StackTrace:
at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
at sqliteTest.Controllers.ValuesController.Get() in C:\Users\FaqeerHussain\source\repos\sqliteTest\sqliteTest\Controllers\ValuesController.cs:line 16
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.
Inner Exception 2:
Exception: Library e_sqlite3 not found
e_sqlite3.dll已经在bin\runtimes\win-x64\native
和bin\runtimes\win-x86\native
了。尝试将x86/x64 e_sqlite3.dll复制到根bin
文件夹,但错误仍然存在。我该怎么做才能让Microsoft.Data.Sqlite工作呢?
发布于 2021-01-18 09:51:57
这是因为Microsoft.Data.Sqlite包与.Net框架的版本不兼容。您可以尝试将NuGet的Microsoft.Data.Sqlite版本更改为2.2.0以正常运行。
发布于 2022-02-08 18:03:20
我发现e_sqlite3.dll位于runtimes\win-x86\native\e_sqlite3.dll.因此,我创建了这些文件夹,并在本机文件夹中添加了e_sqlite3.dll。在那之后就成功了!
发布于 2021-04-06 15:31:16
这是一个尚未修复的已知问题。
我引用了一个.NET标准2.0库,它使用SQLite,来自.NET Framework4.8项目。我将库改为.NET 4.8作为解决方案,因为它没有被任何其他.NET实现使用,我不得不在.NET项目中将<TargetFramework>netstandard2.0</TargetFramework>
更改为<TargetFramework>net48</TargetFramework>
。
https://stackoverflow.com/questions/65750542
复制相似问题