【问题标题】:Could not load Microsoft.SqlServer.Types 10, but version 11 is referenced无法加载 Microsoft.SqlServer.Types 10,但引用了版本 11
【发布时间】:2017-10-12 18:05:43
【问题描述】:

我有一个引用了多个项目的 C# 应用程序。其中一个项目是引用 Microsoft.SqlServer.Types(版本 11),因为它使用的是 SQLGeometry。当我将我的应用程序安装到一台空计算机(仅限带有 VC++ 2010 的 windows 7)时,我的应用程序中出现错误,它“

无法加载文件或程序集“Microsoft.SqlServer.Types, 版本=10.0.0.0,文化=中性,PublicKeyToken=89845dcd8080cc91' 或 它的依赖项之一。

知道为什么它需要第 10 版吗?

【问题讨论】:

    标签: c# sql-server


    【解决方案1】:

    Please refer to this answer.您需要执行以下操作之一:

    1. Type System Version=SQL Server 2012 关键字添加到app.config 中的连接字符串:

    <configuration> <connectionStrings> <add name="YourConnectionStringName" connectionString="(connection string values);Type System Version=SQL Server 2012" /> </connectionStrings> </configuration>

    1. app.config 中为Microsoft.SqlServer.Types 添加bindingRedirect

    <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>

    任一选项都将确保SqlConnection 将加载Microsoft.SqlServer.Types 程序集的11.0.0.0 版本,而不是10.0.0.0 版本。

    【讨论】:

    • 您的计算机上也有可能没有安装版本 11。在这种情况下,您还必须下载 2012 SQL 功能包:microsoft.com/en-us/download/details.aspx?id=29065
    • 对于更高版本,请使用 NuGet 包 &lt;package id="Microsoft.SqlServer.Types" version="14.0.1016.290" targetFramework="net40-client" /&gt;(并参阅作为包的一部分安装的 ReadMe.htm 以查看在运行时加载本机程序集所需的操作)。以及绑定重定向&lt;dependentAssembly&gt; &lt;assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /&gt; &lt;bindingRedirect oldVersion="10.0.0.0-15.0.0.0" newVersion="14.0.0.0" /&gt; &lt;/dependentAssembly&gt;
    【解决方案2】:

    您的解决方案中的某个项目(csproj 文件)或 web/app.config 仍引用版本 10.0.0.0。在解决方案范围内搜索字符串 10.0.0.0,您将找到参考。

    【讨论】:

    • 已经试过了 - 什么也没找到。它似乎试图从 GAC 加载程序集。将尝试将 SpecificVersion 设置为 True。
    • 只是为了补充这个答案,我遇到了这个问题并跟踪了对 web.config 文件的引用。我没想过要去看那里,因为遇到问题的类是具有正确引用的 .dll 文件的一部分(在单独的项目中)。我想我还有一些东西要学,因为我不确定为什么网站参考会适用于从 .dll 实例化的类。
    猜你喜欢
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多