服务器出现“无法加载文件或程序集”错误

9
当我将代码部署到ST服务器时,出现了以下错误。在我的电脑上和开发服务器上,相同的代码可以正常运行,但是访问应用程序中的某些页面时,在ST服务器上会出现此错误。
错误信息如下:
“Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”
问题详细描述:在执行当前Web请求时发生未处理的异常。请查看堆栈跟踪以获取有关该错误及其源代码的更多信息。
这是web.config文件中的内容:
<dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
3个回答

8

通过在web.config文件中添加以下引用,问题已经得到了解决:

  1. Microsoft.Owin
  2. Microsoft.Owin.Security.OAuth
  3. Microsoft.Owin.Security
  4. Microsoft.Owin.Security.Cookies


6

在添加SignalR后,我没有更新服务器上的web.config文件。以下是缺少的内容:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

2
由于在您的本地机器上运行良好,因此有几种可能的情况, 首先,请检查Microsoft.Owin引用是否存在问题,因为在生产环境中可能会出现缺失的情况。 https://www.nuget.org/packages/Microsoft.Owin/2.1.0 您可以在“dependencies”部分进行检查,确保Owin库存在并已引用。
然后,在开发和ST机器上检查GAC(如果您在开发中具有所需版本的程序集,则可以在开发中正常工作,但在ST中没有)。
对于重定向,请确保您拥有正确的xml命名空间。
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0"
                             newVersion="2.0.0.0"/>
         </dependentAssembly>
</assemblyBinding>

包裹您的依赖元素的标记

如果在此之后您仍然无法找到原因,您可以尝试使用随Visual Studio一起提供的工具fuslogvw.exe来获取有关绑定失败的更多信息。


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