Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve System.Web.Http TypeLoadException in Azure role deployment?

In our Azure Cloud Service we use Mvc, WebApi and Autofac.

Mvc and WebApi want System.Web.Http version 5.2.3

Autofac.WebApi2 wants version 5.2.0

When deploying to Azure with version 5.2.3 the web role fails to start with the following error:

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.

So far I've tried adding

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

To a MyAccountView.dll.config and placed it in the approot folder but the error remains the same (including the line about it using the WaIISHost.exe.config).

I've also tried modifying the WaIISHost.exe.config file whilst RDPing onto the instance but I don't think it's using the changed file (if I break the config file by removing the close tag it doesn't complain).

like image 757
Septih Avatar asked Mar 20 '15 11:03

Septih


1 Answers

I was helped by the second paragraph of this answer for similar problem: adding yourwebrolename.dll.config file (with "Copy to Output Directory" : "Copy always" option) in yourwebrole project. More about this solution can be read on this link.

like image 137
e.k Avatar answered Nov 07 '22 19:11

e.k