Freigeben über


FileLoadException on Microsoft.Owin when running on worker role

Do you happen to see FileLoadException when you try to run a OWIN application (SignalR or WebAPI) on a worker role project with the below message?

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Owin, Version=2.0.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)

Reason for the failure:

This is a known issue with Nuget client: Refer this bug. Binding redirects not getting added automatically for worker role projects. The reason for this failure is SignalR/WebAPI binaries are built with a dependency over Microsoft.Owin version 2.0.0. But the latest available version of Microsoft.Owin in the public feed is > 2.0.0. To fix this assembly binding issue when you install the same SignalR/WebAPI packages on a console application or a web application you will see assembly binding redirects being automatically added for you in the app.config by Nuget client. Due to an issue with Nuget client this is not happening in case of worker role projects.

Fix for this issue :

To fix this issue add this to your worker role project's app.config (Alternatively try adding your signalR package to a console app and copy paste the binding redirects from its app.config):

 <configuration>
 <runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <dependentAssembly>
 <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
 <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
 </dependentAssembly>
 <dependentAssembly>
 <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
 <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
 </dependentAssembly>
 </assemblyBinding>
 </runtime>
 </configuration>
  
  

Comments

  • Anonymous
    December 07, 2013
    Good one, saved some of my time :-) Thanks.

  • Anonymous
    January 03, 2014
    Nice.  Appreciate the post.

  • Anonymous
    April 19, 2015
    Good , It works for me! Thanks!

  • Anonymous
    May 27, 2015
    Awesome, thanks for the info, resolved my issue.