vb.net 无法加载文件或程序集“System.Data.SqlServerCE”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22151556/
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-09-17 16:57:42  来源:igfitidea点击:

Could not load file or assembly 'System.Data.SqlServerCE'

sql-servervb.netsql-server-ce

提问by Capellan

I'm trying to connect to an external .sdf file using VB.NET in VS2012. I'm having issues working with the System.Data.SqlServerCE DLL.

我正在尝试在 VS2012 中使用 VB.NET 连接到外部 .sdf 文件。我在使用 System.Data.SqlServerCE DLL 时遇到问题。

When I don't Copy Local I get the error: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

当我不复制本地时,我收到错误:无法加载文件或程序集“System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”或其依赖项之一。该系统找不到指定的文件。

If I do Copy Local I get: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

如果我执行 Copy Local 我得到:无法加载文件或程序集“System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

I have SQL Server Compact version 4 installed, so I'm referencing the DLL in "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private". I've tried adding this DLL from other locations and will get the "Found conflicts between different version of the same dependent assembly" warning. If I click on that it'll add the following to the app.config:

我安装了 SQL Server Compact 版本 4,所以我引用了“C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private”中的 DLL。我已经尝试从其他位置添加此 DLL,并且会收到“在同一依赖程序集的不同版本之间发现冲突”警告。如果我点击它,它会将以下内容添加到 app.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Once that is added to app.config I get this error:

将其添加到 app.config 后,我收到此错误:

Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

无法加载与版本 8876 的 ADO.NET 提供程序相对应的 SQL Server Compact 的本机组件。安装正确版本的 SQL Server Compact。有关更多详细信息,请参阅知识库文章 974247。



One thing I noticed earlier was that System.Data.SqlServerCe was not in the C:\Windows\Microsoft.NET\assembly folder. I installed the DLL using gacutil.exe and changed the

我之前注意到的一件事是 System.Data.SqlServerCe 不在 C:\Windows\Microsoft.NET\assembly 文件夹中。我使用 gacutil.exe 安装了 DLL 并更改了

<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>

in app.config to

在 app.config 中

<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>

(4.0.0.0 is the version listed by the gacutil).

(4.0.0.0 是 gacutil 列出的版本)。

This got me past the assembly errors at least. :)

这至少让我克服了装配错误。:)

It's too soon to post an answer for myself, so I'll just leave this edit.

现在为自己发布答案还为时过早,所以我将离开此编辑。

采纳答案by Dilhan RK

I manage to fixed the above issue by using C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll. So the System.Data.SqlServerCe.dll in path C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private doesn't work.

我设法通过使用 C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll 解决了上述问题。因此,路径 C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private 中的 System.Data.SqlServerCe.dll 不起作用。