即使使用了“复制到本地”选项,仍然无法加载文件或程序集“Microsoft.SqlServer.Types”。

23

我在我的Web应用程序上有一个内部报告,当我本地浏览时,它显示如预期。我使用rdlcxsd以及标准的apsx网页来呈现报告。

我现在已经部署到了我的测试服务器上,但是当我尝试浏览显示报告的页面时,出现以下错误:

An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.SqlServer.Types, Version=11.0.0.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)

在本地,我通过浏览以下路径添加了对Microsoft.SqlServer.Types的引用:

C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91

我已将其设置为Copy Local并可以在预发布服务器的bin文件夹中看到.dll,但仍然收到错误消息。

有趣的是,我从我的本地计算机复制了.dll,并将其ftp到了预发布服务器上并放到了bin文件夹中。它能正常工作,但只是临时的,直到我进行另一个提交,它会抹掉bin文件夹并且错误会再次出现。

好像预发布服务器的操作系统上的Microsoft.SqlServer.Types的版本过时了?

这里发生了什么?

7个回答

24

我也遇到了同样的问题,但问题是app.config文件中的绑定重定向未更新到新版本。通常升级NuGet包会自动完成此操作,但此NuGet包位于引用的项目中。修复方法如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings />
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <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" /> -->
        <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

2
尽管我已经通过NuGet包引用了Microsoft.SqlServer.Types,但我还是不得不手动将上述assemblyBinding条目添加到我的web.config文件中。看起来Web应用程序试图从GAC加载旧版本而不是我引用的版本。 - lukiller
我这里也是,在 web.config 中没有引用,但是一旦我添加了 dependentAssembly,它就起作用了。 - FarFigNewton

22

1
只是工作,非常感谢。 - JsonStatham

3

我复制了文件

(我的解决方案目录)\packages\Microsoft.SqlServer.Types.14.0.314.76\lib\net40\Microsoft.SqlServer.Types.dll

到“/bin”目录中。
这样就解决了我的问题。


1
在我的情况下,这个文件应该在发布时自动出现,但不知何故没有复制到BIN文件夹中。当我再次创建发布时,这个文件自动复制到了BIN文件夹中。 - Zeeshanef
1
我也不得不做同样的事情。唯一的区别是版本号是11.0.0.0。一旦我将Microsoft.SqlServer.Types.11.0.0.0从packages文件夹复制到Bin目录中,问题就解决了。 - Shiva Naru

2

经历了同样的问题,这是在升级Visual Studio和Sql Server实例后发生的。

下载并重新安装以下内容后,问题已解决:

希望能对某些人有所帮助。


重新安装SQLSysCLRTypes.msi解决了我的问题,但上面的链接并没有带您到正确的页面。截至2022年5月1日,正确的网址是https://www.microsoft.com/en-us/download/details.aspx?id=100451。 - Avi
我添加了 Avi 提供的链接。这个链接可能是 ReportViewer.msi,但我自己还没有尝试过。 - surfmuggle

2

我在新的工作站上无法编译我的程序,使用了以下代码:

    <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>

问题? 微软默认提供的 SQL Express 服务器在此期间从 2017 更改为 2019,我没有注意到,因此必须将 newVersion 设置为 newVersion="15.0.0.0"


<!--注释此部分--> <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> 适用于我。 - Giancarlo Molina

0

安装nuget包后,从C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types中复制Microsoft.SqlServer.Types.dll文件
到我的宿主Web服务器上我的Web应用程序的BIN文件夹中。


0
在Web.config文件中,只需将oldVersion="0.0.0.0-14.0.0.0"更改为oldVersion="14.0.0.0-14.0.0.0",与您实际安装的版本相同。
>runtime>中: <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="14.0.0.0-14.0.0.0" newVersion="14.0.0.0" /> </dependentAssembly>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接