【问题标题】:Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0' or one of its dependencies无法加载文件或程序集“Microsoft.SqlServer.Types,Version=10.0.0.0”或其依赖项之一
【发布时间】:2018-04-10 03:35:43
【问题描述】:

最近我开始使用 SSMS 2017 (v17.5)。在我的 MVC 应用程序中,我收到 Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. 错误。我的应用程序中唯一改变的是Microsoft.SqlServer.Types 版本,现在是14.0.0.0。以前,它是12.0.0.0。

以下是我迄今为止根据我的研究尝试过的不同选项(这包括另一篇 stackoverflow 文章 + google),但我遇到了同样的错误。

  1. 在app.config中添加<dependentAssembly>

    <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" /> </dependentAssembly>

  2. 在Application_Start 方法的Global.asax.cs 中添加以下行。

    SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";

  3. 使用NuGet 安装Microsoft.SqlServer.Types。

    PM&gt; Install-Package Microsoft.SqlServer.Types

  4. 在整个项目中搜索 10.0.0.0 引用,但未找到任何引用。

  5. 我确实为2012, 2014, 2016 和2017 安装了Microsoft System CLR Types for SQL Server。

我在这里错过了什么?

【问题讨论】:

  • 我假设您的查询是针对 SQL Server 2017 运行的?你的表有hierarchyid 列吗?
  • @AaronBertrand 是的,它针对 2017 年运行。不,该表没有 hierarchyid。
  • 还有其他古怪的数据类型吗?您能否将CREATE TABLE 连同索引一起显示?
  • @CSharper 构建是在本地失败还是在远程服务器上失败?另外,当您提到搜索该程序集时,您是否通过解决方案资源管理器进行搜索?在解决方案上方的“搜索解决方案资源管理器”文本字段中,输入Microsoft.SqlServer.Types,然后您将看到所有引用它的项目。检查每个对 Microsoft.SqlServer.Types 的引用的属性,看看哪个是针对 10.0.0.0
  • @AlwaysLearning 我刚刚找到了解决方案并在下面添加了我的答案。希望这是有道理的。谢谢。

标签: c# sql-server


【解决方案1】:

花了将近一天的时间后,我能够解决这个问题。根据我上面的问题,选项 1 对我有用。唯一的调整是将其添加到web.config 而不是app.config。希望这对其他人有帮助。

代码:web.config

<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-14.0.0.0" newVersion="14.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>

【讨论】:

  • 谢谢,这个提示引导我进行修复。不过不太一样。通过 VS,我添加(重新?)为项目添加了对 Microsoft.SqlServer.Types 的引用(右键单击项目,添加引用,在扩展下)。它添加了版本 13。在我的 web.config 中,我只是将 Version=10.0.0.0 更改为 Version=13.0.0.0 。设法破解了这个我可能 2 年没碰过的旧应用程序......
【解决方案2】:

Microsoft.SqlServer.Types -版本 14.0.314.76 是当前版本。尝试更改您的版本号。其次,检查你的 .csproj 文件,Application 也在 .csproj 文件中维护它的依赖关系

【讨论】:

  • 我的.csproj 文件版本相同。
  • 然后尝试清理您的项目,删除所有 bin/lib,然后重建您的项目(如果您还没有尝试过)。
  • 那也没用。
猜你喜欢
  • 2022-12-04
  • 2020-11-03
  • 1970-01-01
  • 1970-01-01
  • 2014-07-24
  • 2014-02-02
  • 1970-01-01
  • 2018-09-03
  • 2014-02-17
相关资源
最近更新 更多