【问题标题】:How to solve System.Web.Http TypeLoadException in Azure role deployment?Azure 角色部署中如何解决 System.Web.Http TypeLoadException?
【发布时间】:2015-05-23 19:30:22
【问题描述】:

在我们的 Azure 云服务中,我们使用 Mvc、WebApi 和 Autofac。

Mvc 和 WebApi 想要 System.Web.Http 版本5.2.3

Autofac.WebApi2 想要 5.2.0

版本

使用 5.2.3 版部署到 Azure 时,Web 角色无法启动并出现以下错误:

WaIISHost
Role entrypoint could not be created: System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=5.2.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)
File name: 'System.Web.Http, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///E:/approot/bin
LOG: Initial PrivatePath = E:\approot\bin
Calling assembly : Autofac.Integration.WebApi, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\base\x64\WaIISHost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from D:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Http, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///E:/approot/bin/System.Web.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

到目前为止,我已经尝试添加

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>

到 MyAccountView.dll.config 并将其放在 approot 文件夹中,但错误仍然存​​在(包括使用 WaIISHost.exe.config 的行)。

我也尝试过修改 WaIISHost.exe.config 文件,同时 RDPing 到实例上,但我认为它没有使用更改后的文件(如果我通过删除关闭标签来破坏配置文件,它不会抱怨) .

【问题讨论】:

    标签: azure asp.net-web-api autofac


    【解决方案1】:

    我遇到了同样的错误,我通过在我的 web.config 文件中添加以下内容解决了它

        <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35"      />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    

    我可以看到你正在使用

    把旧版本改成0.0.0.0-5.2.2.0,你现在是这样的

    【讨论】:

      【解决方案2】:

      answer 的第二段帮助我解决了类似的问题:在 yourwebrole 项目中添加 yourwebrolename.dll.config 文件(带有“复制到输出目录”:“始终复制”选项)。有关此解决方案的更多信息,请参阅link

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多