C# System.IO.FileLoadException: 无法加载文件或程序集“System.Data.SQLite”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18181018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:28:57  来源:igfitidea点击:

System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite

c#winformssystem.data.sqlite

提问by mjb

(This is a duplicated question which has been asked in stackoverflow.com. I have read the answers. I've tried the solutions, but that didn't solve my problem. I'm going to explain what my problem is and what have I done).

(这是一个重复的问题,已在 stackoverflow.com 中提出。我已阅读答案。我尝试了解决方案,但这并没有解决我的问题。我将解释我的问题是什么以及有什么我完成了)。

This is my problem:

这是我的问题:

My application used System.Data.SQLite.DLL. I referenced it and run normally in my computer, but it failed to run on another computer. This is the error message:

我的应用程序使用 System.Data.SQLite.DLL。我引用了它,在我的电脑上正常运行,但在另一台电脑上运行失败。这是错误消息:

System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
(Exception from HRESULT: 0x800736B1) File name: 'System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' ---> System.Runtime.InteropServices.COMException (0x800736B1): The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
(Exception from HRESULT: 0x800736B1) at SimPB.config.PrepareDatabase() at SimPB.config.InitializeProgram() at SimPB.Program.Main()

System.IO.FileLoadException:无法加载文件或程序集“System.Data.SQLite,版本=1.0.88.0,Culture=neutral,PublicKeyToken=db937bc2d44ff139”或其依赖项之一。应用程序无法启动,因为其并行
配置不正确。请查看应用程序事件日志或使用命令行 sxstrace.exe 工具获取更多详细信息。
(来自 HRESULT 的异常:0x800736B1)文件名:'System.Data.SQLite,Version=1.0.88.0,Culture=neutral,PublicKeyToken=db937bc2d44ff139'---> System.Runtime.InteropServices.COMException(0x800736B1):应用程序失败开始,因为它并排
配置不正确。请查看应用程序事件日志或使用命令行 sxstrace.exe 工具获取更多详细信息。
(来自 HRESULT 的异常:0x800736B1)在 SimPB.config.PrepareDatabase() 在 SimPB.config.InitializeProgram() 在 SimPB.Program.Main()

My computer is running Windows 7 32 bit, Visual Studio 2010.

我的电脑运行的是 Windows 7 32 位,Visual Studio 2010。

Another computer is running Windows 7 32 bit too, without Visual Studio installed.

另一台计算机也运行 Windows 7 32 位,但未安装 Visual Studio。

What I have tried:

我尝试过的:

Attempt 1:Make sure the application is build with Release + x86and the application is build with the target framework: .NET Framework 2.0. Done.

尝试 1:确保应用程序是使用Release + x86构建的,并且应用程序是使用目标框架构建的:.NET Framework 2.0。完毕。

Attempt 2:Make sure the application referenced with the correct build of System.Data.SQLite, which is x86 + .Net Framework 2.0 (sqlite-netFx20-binary-Win32-2005-1.0.88.0). Done

尝试 2:确保使用 System.Data.SQLite 的正确版本引用的应用程序,即 x86 + .Net Framework 2.0 (sqlite-netFx20-binary-Win32-2005-1.0.88.0)。完毕

Attempt 3:Try these codes at App.config:

尝试 3:在 App.config 中尝试这些代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

and this

和这个

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <NetFx40_LegacySecurityPolicy enabled="true"/>
  </runtime>
</configuration>

and this

和这个

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

Done.

完毕。

Attempt 4:Try turn off User Account Control on the another computer. Done.

尝试 4:尝试关闭另一台计算机上的用户帐户控制。完毕。

Attempt 5:Try install Visual C++ Runtime on the another computer (I install Visual Microsoft Visual C++ Runtime 2010 Redistributable Package (x86), also tried 2005 verson.). Done.

尝试 5:尝试在另一台计算机上安装 Visual C++ Runtime(我安装了 Visual Microsoft Visual C++ Runtime 2010 Redistributable Package (x86),也尝试了 2005 版本)。完毕。

Attempt 6:Try reinstall .NET Framework 2.0 SP2. Receive error:

尝试 6:尝试重新安装 .NET Framework 2.0 SP2。接收错误:

You must use "Turn Windows Features On or Off" in the Control Panel to install or configure Microsoft .NET Framework 2.0 SP2.

您必须使用控制面板中的“打开或关闭 Windows 功能”来安装或配置 Microsoft .NET Framework 2.0 SP2。

Updated: (After reading answers and comments)
Attempt 7:Make sure System.Data.SQLite.DLL is located at the output bin folder. Done

更新:(阅读答案和评论后)
尝试 7:确保 System.Data.SQLite.DLL 位于输出 bin 文件夹中。完毕

Attempt 8:Double confirm that the another computer is running 32bit Windows 7. Done

尝试 8:再次确认另一台计算机运行的是 32 位 Windows 7。完成

Attempt 9:Change the HintPath declaration in .csproj file:
Change this:

尝试 9:更改 .csproj 文件中的 HintPath 声明:
更改此:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>E:\Developer Soft\SQLite\sqlite-netFx20-binary-bundle-Win32-2005-1.0.88.0\System.Data.SQLite.dll</HintPath>
</Reference>

To this:

对此:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>..\System.Data.SQLite.dll</HintPath>
</Reference>

Done for Attempt 9.

完成尝试 9。

After the above attempts, the result is still the same. The application can run from my computer normally and failed to run on the another computer.

经过以上尝试,结果还是一样。该应用程序可以在我的计算机上正常运行,但在另一台计算机上无法运行。

This is an open source freeware, Simple Phone Book. I have committed and uploaded the latest source code to it's source control server at:
http://simpb.codeplex.com/SourceControl/list/changesets(Changeset Number: fd847ac6c406)

这是一个开源免费软件,简单电话簿。我已将最新的源代码提交并上传到它的源代码控制服务器:
http://simpb.codeplex.com/SourceControl/list/changesets(变更集编号:fd847ac6c406)

采纳答案by mjb

I have solved the problem. This is how I solve:

我已经解决了这个问题。我是这样解决的:

Short story:
Use older version of System.Data.SQLite. New version is suspected to have bugs (I could be wrong).

小故事:
使用旧版本的 System.Data.SQLite。新版本怀疑有错误(我可能是错的)。

Long story:
I started to recall back why my previous old version of this program is able to be executed on other computer and this new version can't. What are the obvious changes that I have made?

长话短说:
我开始回忆为什么我以前的这个程序的旧版本可以在其他计算机上执行而这个新版本不能。我做了哪些明显的改变?

Yes, I have changed the version of System.Data.SQLite.

是的,我已经更改了 System.Data.SQLite 的版本。

The old version of System.Data.SQLite used by this program is V1.0.66. The new version that I used is the latest version: V1.0.88, released on 8 August 2013. (Yes, which is about 4 days agofrom today). Read more: http://system.data.sqlite.org/index.html/timeline

本程序使用的 System.Data.SQLite 旧版本为V1.0.66。我使用的新版本是最新版本:V1.0.88,2013年8月8日发布。(是的,从今天开始大约是4 天前)。阅读更多:http: //system.data.sqlite.org/index.html/timeline

Then I decided to abondon the new version (V1.0.88) and used the old version (V1.0.66), and everything back to normal. The program is once again executable on another computer.

然后我决定放弃新版本(V1.0.88)并使用旧版本(V1.0.66),一切恢复正常。该程序再次可以在另一台计算机上执行。

I have tried to have a look at the source code of V1.0.88, but I failed to locate the lines of code which causes the problem. The best I can discovered is at the project of System.Data.SQLite.Interop. When I load the solution in Visual Studio 2010, System.Data.SQLite.Interopis preset to build for .NET Framework 4.0. I don't know how to change it. Later, I reload the solution in Visual Studio 2008, the common properties of System.Data.SQLite.Interopshowing that it is going to build for .NET Framework 2.0 (which is what I'm looking for), but I fail to build the solution. Some build errors occur. I didn't spend the time to debug it.

我曾尝试查看V1.0.88的源代码,但未能找到导致问题的代码行。我能发现的最好的是System.Data.SQLite.Interop项目。当我在 Visual Studio 2010 中加载解决方案时,System.Data.SQLite.Interop预设为针对 .NET Framework 4.0 构建。我不知道怎么改。后来,我在 Visual Studio 2008 中重新加载了解决方案,System.Data.SQLite.Interop的通用属性表明它将为 .NET Framework 2.0(这是我正在寻找的)构建,但我无法构建解决方案。发生一些构建错误。我没有花时间调试它。

I need to develop the program for .NET Framework 2.0, because there are users who are still using Windows XP.

我需要为.NET Framework 2.0 开发程序,因为有些用户还在使用Windows XP。

I assume that V1.0.88contains bugs, but I could be wrong. Anyway, as for current solution, I just stick to V1.0.66.

我假设V1.0.88包含错误,但我可能是错的。无论如何,至于当前的解决方案,我只是坚持V1.0.66

回答by Cristian Lupascu

The assembly cannot be located due to a HintPath declaration in your .csproj file:

由于.csproj 文件中的 HintPath 声明,无法定位程序集:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>E:\Developer Soft\SQLite\sqlite-netFx20-binary-bundle-Win32-2005-1.0.88.0\System.Data.SQLite.dll</HintPath>
</Reference>

It works on your machine, because you really have the .dll at that location. However, the other person may want to use the System.Data.SQLite.dll file you placed in the root of the repository. Since that is one level up from the .csproj, you can use a relative path, like this:

它适用于您的机器,因为您确实在该位置拥有 .dll。但是,其他人可能想要使用您放置在存储库根目录中的 System.Data.SQLite.dll 文件。由于这是 .csproj 的上一级,因此您可以使用相对路径,如下所示:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>..\System.Data.SQLite.dll</HintPath>
</Reference>

and it should work fine.

它应该可以正常工作。

回答by jruizaranguren

I also have had problems with SQLite since v1.0.66 in x64/x86 machines. I have never been able to install ServiceStack and then SqLite.x86 with the nuget package and have it working out of the box.

我在 x64/x86 机器上自 v1.0.66 以来也遇到过 SQLite 问题。我从来没有能够用 nuget 包安装 ServiceStack 和 Sqlite.x86 并让它开箱即用。

But today I have changed the installing process with succes, and it might be a solution also for you. I suspect that the problem is allways that the version of System.Data.SQlite is not aligned with the one Servicestack.Ormlite.SqliteNET expects.

但是今天我已经成功地更改了安装过程,它也可能是您的解决方案。我怀疑问题始终在于 System.Data.SQlite 的版本与 Servicestack.Ormlite.SqliteNET 期望的版本不一致。

The next process in Nuget console makes things work for me:

Nuget 控制台中的下一个过程对我有用:

Install-Package System.Data.Sqlite.x86 -Version 1.0.88.0
Install-Package ServiceStack -Version 3.9.71
Install-Package ServiceStack.OrmLite.Sqlite32 -Version 3.9.71

回答by Leng Weh Seng

Check if MS Visual C++ running redistributable install, as System.Data.SQLite is depend on it.

检查 MS Visual C++ 是否运行可再发行安装,因为 System.Data.SQLite 依赖于它。

回答by Coder1224

In your App.config file, add these lines inside the <configuration>element:
<runtime> <loadFromRemoteSources enabled="true"/> </runtime>

在您的 App.config 文件中,在<configuration>元素中添加以下几行:
<runtime> <loadFromRemoteSources enabled="true"/> </runtime>