如何在Azure角色部署中解决System.Web.Http TypeLoadException?

Sep*_*tih 7 azure autofac asp.net-web-api

在我们的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.
Run Code Online (Sandbox Code Playgroud)

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

  <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>
Run Code Online (Sandbox Code Playgroud)

到MyAccountView.dll.config并将其放在approot文件夹中,但错误保持不变(包括使用WaIISHost.exe.config关于它的行).

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

cod*_*sin 0

我遇到了同样的错误,我通过在 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>
Run Code Online (Sandbox Code Playgroud)

我可以看到你正在使用

将旧版本更改为 0.0.0.0-5.2.2.0,目前您的版本为