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=, 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):

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="" newVersion="" />
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="" newVersion="" />
Comments (4)

  1. James says:

    Good one, saved some of my time 🙂


  2. Dave says:

    Nice.  Appreciate the post.

  3. Darren says:

    Good , It works for me! Thanks!

  4. Sam says:

    Awesome, thanks for the info, resolved my issue.