无法加载文件或程序集SQLitePCLRaw.core。

8
我正在使用Microsoft.EntityFrameworkCore.Sqlite版本2.2.4和Microsoft.EntityFrameworkCore版本2.2.4的nuget包,用于我的.net core类库。
当我将我的类库添加到控制台应用程序中时,我遇到了以下异常: FileNotFoundException: Could not load file or assembly 'SQLitePCLRaw.core, Version=1.1.12.351, Culture=neutral, PublicKeyToken=1488e028ca7ab535'. The system cannot find the file specified.
我的代码在Windows上运行,但也将在Linux上运行。
有没有解决方案?
我看到有人建议将Microsoft.EntityFrameworkCore.Sqlite nuget添加到我的控制台应用程序中。 但我更喜欢避免这种解决方案。

3
尝试添加对Microsoft.Data.Sqlite包的引用,并在程序开头调用Batteries.Init(); - Lasse V. Karlsen
在添加了Microsoft.Data.Sqlite并调用Batteries.Init()之后,我遇到了新的错误:无法加载文件或程序集'SQLitePCLRaw.batteries_green, Version=1.1.12.351, Culture=neutral, PublicKeyToken=a84b7dcfb1391f7f'。系统找不到指定的文件。 - user1551454
调用 Batteries.Init() 也解决了我的问题。找了一天才找到这篇帖子!但你需要安装这个包:SQLitePCLRaw.bundle_green。 - user2410689
3个回答

3

我曾经遇到同样的问题,而采取以下步骤解决了它:

  1. 删除 obj 和 bin 文件夹
  2. 运行 dotnet restore --force

在得到这个建议后,出现了11987个错误,这不是一个好的解决方案。无法回退,帮助极差。 - Jonas
1
因为这个问题,需要重新安装Visual Studio =( - Jonas
在Linux上使用Rider工作得很好,尽管没有修复丢失的dll文件。 - Tin Svagelj

2

我不得不降级到一个较低的版本。

<PackageReference Include="sqlite-net-pcl" Version="1.6.292" />
<!--<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />-->

这个解决方案对我有用(但是从VS22 NuGet Packages界面)。我遵循了一些教程指令。我猜测sqlite-net-pcl的新依赖项做了一些在制作该教程时意想不到的事情。 - carloswm85

0

刚遇到了这个问题 - 在我的.csproj文件中,某些内容将AutoGenerateBindingRedirects设置为false。将其恢复为true就解决了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接