4
votes

I am trying to run SignalR self host server in the Windows Azure Worker Role, but keep getting the

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)

When I run the same code in the console application it runs fine and everything works as expected. The whole worker role is written in F#. Below is the shortest code which produces the exception I am talking about:

override wr.Run() =
    let x : IAppBuilder = null

    x.MapSignalR() |> ignore // this line throws the FileLoadException

exception

Of course the code above should not work, but with different exception. Normally I call MapSignalR in the Configuration() method of the Startup class (WebApp.Start(url)).

The exception detail I pasted is from the Compute emulator, but I get the same thing at the live Cloud Service.

Do you have any idea what can cause the problem or how can I diagnose it further?

3

3 Answers

7
votes

This is a known issue with Nuget : Refer this. Binding redirects not getting added automatically for worker role projects. The reason for this failure is SignalR 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.2. To fix this assembly binding issue when you install the same SignalR packages on a console application or a web application you will see assembly binding redirects being automatically added for you in the app.config. Due to an issue with Nuget client this is not happening in case of worker role projects. 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):

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

If The accepted answer does not work for you issue the following 2 commands in the package manager console:

update-package Microsoft.Owin -version 2.x.x
update-package Microsoft.Owin.Security -version 2.x.x

Where 2.x.x is the version that the exception complains about.

For me the version number was 2.0.1.

After that make sure that you have the following in your application's config file (configuration section):

<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.1.0" newVersion="2.x.x.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.x.x.0" />
  </dependentAssembly>
</assemblyBinding>
</runtime>
0
votes

Adding the binding above did not resolve the issue for me. I had to manually edit the .csproj file.

  • 'Right-click' the project and select 'Unload Project' and then 'right-click' project and hit 'edit'.

  • From there, I had to clean up the nodes for the Owin assemblies. My Owin assemblies were not being loaded from the relative NuGet packages directory and thus were loading 2.0.0.

BEFORE:

-    <Reference Include="Microsoft.Owin">
-      <HintPath>..\packages\Microsoft.Owin.2.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
-    </Reference>
-    <Reference Include="Microsoft.Owin.Host.SystemWeb">
-      <HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
-    </Reference>
-    <Reference Include="Microsoft.Owin.Security">
-      <HintPath>..\packages\Microsoft.Owin.Security.2.0.0\lib\net45\Microsoft.Owin.Security.dll</HintPath>
-    </Reference>
-    <Reference Include="Microsoft.Owin.Security.Facebook">
-      <HintPath>..\packages\Microsoft.Owin.Security.Facebook.2.0.0\lib\net45\Microsoft.Owin.Security.Facebook.dll</HintPath>
-    </Reference>
-    <Reference Include="Microsoft.Owin.Security.Cookies">
-      <HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.0\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
-    </Reference>
-    <Reference Include="Microsoft.Owin.Security.OAuth">
-      <HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
-    </Reference>

AFTER:

+    <Reference Include="Microsoft.AspNet.Identity.Owin">
+      <HintPath>..\packages\Microsoft.AspNet.Identity.Owin.1.0.0\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Owin.Security, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Owin.Security.2.0.2\lib\net45\Microsoft.Owin.Security.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Owin.Security.Cookies, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.2\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Owin.Security.OAuth, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.2\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Owin.Host.SystemWeb, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.2\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
+    </Reference>
  • Finally, 'Right-click' the project and select 'Reload Project'.
  • Open up the 'References' for the project and verify it is loading the correct version from the correct location on your system.