定期我得到以下异常:
无法加载DLL 'SQLite.Interop.dll':无法找到指定的模块。(异常来自HRESULT: 0x8007007E)
我使用的是1.0.82.0。在VS2010, Win7 64操作系统下使用nuget安装。
一旦异常开始出现,它就会不断出现——在调试和发布中,在VS内部或外部运行应用程序。
阻止它的唯一方法就是退出并重新登录。不抛出异常并加载dll。 它可以工作几天,但之后又会坏掉。
有人见过这样的情况吗,有解决方案吗?
定期我得到以下异常:
无法加载DLL 'SQLite.Interop.dll':无法找到指定的模块。(异常来自HRESULT: 0x8007007E)
我使用的是1.0.82.0。在VS2010, Win7 64操作系统下使用nuget安装。
一旦异常开始出现,它就会不断出现——在调试和发布中,在VS内部或外部运行应用程序。
阻止它的唯一方法就是退出并重新登录。不抛出异常并加载dll。 它可以工作几天,但之后又会坏掉。
有人见过这样的情况吗,有解决方案吗?
当前回答
当您处于这种状态时,尝试执行Rebuild-All。如果这解决了问题,您可能会遇到与我相同的问题。
一些背景(我的理解):
SQLite has 1 managed assembly (System.Data.SQLite.dll) and several platform specific assemblies (SQLite.Interop.dll). When installing SQLite with Nuget, Nuget will add the platform specific assemblies to your project (within several folders: \x86, \x64), and configures these dlls to "Copy Always". Upon load, the managed assembly will search for platform specific assemblies inside the \x86 and \x64 folders. You can see more on that here. The exception is this managed assembly attempting to find the relevant (SQLite.Interop.dll) inside these folders (and failing).
我的情况:
我的解决方案中有两个项目;一个WPF应用程序和一个类库。WPF应用程序引用类库,类库引用SQLite(通过Nuget安装)。
对我来说,问题是当我只修改WPF应用程序时,VS试图进行部分重建(意识到依赖的dll没有改变)。在这个过程的某个地方,VS清理了\x86和\x64文件夹的内容(清除了SQLite.Interop.dll)。当我做一个完整的Rebuild-All时,VS正确地复制文件夹及其内容。
我的解决方案:
为了解决这个问题,我添加了一个Post-Build进程,使用xcopy强制将\x86和\x64文件夹从类库复制到我的WPF项目\bin目录。
或者,您可以使用构建配置/输出目录做一些更花哨的事情。
其他回答
我在一个WebAPI/MVC5 web项目和一个特性测试项目的解决方案中遇到了这个问题,这两个项目都来自同一个数据访问(或“核心”)项目。像这里的许多人一样,我使用的是通过NuGet在Visual Studio 2013中下载的副本。
What I did, was in Visual Studio added a x86 and x64 solution folder to the Feature Test and Web Projects. I then did a Right Click | Add Existing Item..., and added the appropriate SQLite.interop.dll library from ..\SolutionFolder\packages\System.Data.SQLite.Core.1.0.94.0\build\net451\[appropriate architecture] for each of those folders. I then did a Right Click | Properties, and set Copy to Output Directory to Always Copy. The next time I needed to run my feature tests, the tests ran successfully.
如果您下载了正确的SQLite二进制文件,则根据项目构建选项将SQLite. interop .dll复制到您的发布或调试文件夹中。
升级到Visual Studio 2019版。16.10导致了我的问题,其中msbuild报告了以下System.Data.SQLite.Core-package:
CopySQLiteInteropFiles:
Skipping target "CopySQLiteInteropFiles" because it has no outputs.
https://github.com/dotnet/msbuild/issues/6493
微软表示,该漏洞已被修复。16.10.4. 现在只需要等待AppVeyor更新他们的Visual Studio图像(在此之前,可以使用以前的Visual Studio 2019)。
现在,AppVeyor正在为当前和以前的Visual Studio 2019-image使用破碎的dotnet-build-engine。现在一个必须显式安装dotnet sdk ver。5.0.302:
Invoke-WebRequest -Uri 'https://dot.net/v1/dotnet-install.ps1' -UseBasicParsing -OutFile "$env:temp/dotnet-install.ps1"; & $env:temp\dotnet-install.ps1 -Architecture x64 -Version 5.0.302 -InstallDir "$env:ProgramFiles\dotnet"
对于任何关注这个问题的人来说:
如果您使用nuget包,它会安装一个构建规则,为您执行复制。(参见System.Data.SQLite.Core.1.0.94.0\build -或任何你安装的Core版本)。
nuget安装程序会自动将规则添加到项目文件中。
但是,这仍然不能解决测试用例问题。deploymenttem (https://stackoverflow.com/a/24411049/89584)方法似乎是惟一可行的方法。
旧项目文件格式
即以<Project ToolsVersion="3.5" DefaultTargets="Build"开头的项目xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
将以下内容添加到“主”/根项目的csproj中
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
新的SDK项目文件格式
例如,以<Project Sdk="Microsoft.NET.Sdk.*"开头的项目>
将PrivateAssets="none"添加到System.Data.Sqlite PackageImport依赖链中的每个ProjectReference/PackageImport
ex:
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.110" PrivateAssets="none"/>