定期我得到以下异常:

无法加载DLL 'SQLite.Interop.dll':无法找到指定的模块。(异常来自HRESULT: 0x8007007E)

我使用的是1.0.82.0。在VS2010, Win7 64操作系统下使用nuget安装。

一旦异常开始出现,它就会不断出现——在调试和发布中,在VS内部或外部运行应用程序。

阻止它的唯一方法就是退出并重新登录。不抛出异常并加载dll。 它可以工作几天,但之后又会坏掉。

有人见过这样的情况吗,有解决方案吗?


当前回答

因此,在添加了NuGet之后,部署不会复制Interops。你可以把这个添加到你的csproj文件中,它应该会修复这个行为:

 <PropertyGroup> 
    <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
    <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
    <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
    <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
 </PropertyGroup>

如果你看一下NuGet for SQLite的源代码,你可以看到这些具体在做什么。这允许我使用ASP进行部署。净的核心。

其他回答

我不知道这是否是一个好的答案,但我能够通过在AppDomain下以“本地系统”的身份运行我的应用程序来解决这个问题。

大会上会有竞争吗?检查DLL上是否有其他具有文件锁的应用程序。

如果是这个原因,使用Sysinternal的Process Explorer之类的工具来发现有问题的程序应该很容易。

HTH, 粘土

所以,我的问题是SQLite试图在WPF的设计时加载。由于我只关心x86环境,所以我将CPU首选项设置为x86环境,并将Nuget包中的SQLite.Interop.dll复制到解决方案的根目录。重新启动解决方案,所有问题都消失了。因此,如果遇到设计时问题,请将库放到解决方案的根目录中。

此外,我在运行时遇到了类似的问题,所以我必须将SQLite.Interop.dll的副本放入我的项目中,并将其设置为复制,如果它在属性中较新的。似乎x86和x64提供的文件夹是完全无用的。还需要进一步的调查,但总的来说…在你的项目中手动引用SQLite比使用Nuget包更容易。

此外,官方常见问题解答如下:

(20) When the System.Data.SQLite project is compiled and run from inside Visual Studio, why do I get a DllNotFoundException or a BadImageFormatException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run or debug the application? When compiling and running a solution from within Visual Studio that uses the System.Data.SQLite project (including the test project), it is very important to select the correct build configuration and platform. First, managed applications to be debugged inside Visual Studio cannot use the mixed-mode assembly (i.e. because it is always compiled to the platform-specific build output directory). This is necessary to properly support building binaries for multiple platforms using the same source project files. Therefore, only the "DebugNativeOnly" or "ReleaseNativeOnly" build configurations should be selected when running a managed application from inside Visual Studio that relies upon the System.Data.SQLite assembly. These build configurations contain a custom post-build step that copies the required native assembly to the managed output directory (i.e. to enable running the managed binaries in-place). However, this post-build step will only be performed if the selected platform matches that of the operating system (e.g. "Win32" for 32-bit Windows and "x64" for 64-bit Windows). Therefore, it is good practice to double-check the selected build platform against the operating system prior to attempting to run a managed project in the solution.

https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q20

简而言之

为了让它也能与NCrunch一起工作,我必须在NCrunch配置中添加与NuGet包一起提供的Interop.dll版本作为附加文件。

我的情况

我有一个c#解决方案,其中一个项目直接依赖于SQLite(一个帮助库)和一个使用这个帮助库的单元测试项目。我已经安装了System.Data.SQLite.Core版本1.0.97.0作为NuGet包。

在我的案例中,Marin提供的解决方案使它可以在Visual Studio和CI中工作。然而,这仍然会在NCrunch中提供错误。

在NCrunch配置中,我在单元测试项目设置下的“附加文件”中添加了以下路径:

..\packages\System.Data.SQLite.Core.1.0.97.0\build\net45\**.dll

这是我在我的项目中解决它的方法。

它正在工作,当一位同事提交他的更改时,我收到了“无法加载DLL 'SQLite.Interop.dll'”异常。

区别项目的.csproj文件,这是在NON-WORKING版本中:

<ItemGroup>
     <Content Include="x64\SQLite.Interop.dll" />
     <Content Include="x86\SQLite.Interop.dll" />
</ItemGroup>

下面是WORKING版本的内容:

<ItemGroup>
     <Content Include="x64\SQLite.Interop.dll">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
      <Content Include="x86\SQLite.Interop.dll">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
</ItemGroup>

在返回之后,我没有收到异常。DLL文件被转储到适当的Debug\x64 (etc)文件夹中。