SignalR 2.0 error: Could not load file or assembly

2019-02-07 15:55发布

I'm following this tutorial step by step

http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host

And I'm getting an exception on the line marked below

        string url = "http://localhost:8080";
        using (WebApp.Start(url)) //<------ error on this line
        {
            Console.WriteLine("Server running on {0}", url);
            Console.ReadLine();
        }

Error message:

Could not load file or assembly 'Microsoft.Owin.Security, Version=2.0.1.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)

More info:

In my project solution, the reference is pointing to the dll in the packages folder from NuGet

This has been added in my App.config file by NuGet

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

In the packages folder, packages\Microsoft.Owin.Security.2.0.0\lib\net45, the file version of Microsoft.Owin.Security.dll is 2.020911.395

9条回答
Summer. ? 凉城
2楼-- · 2019-02-07 16:49

Simple, Go to your web.config file. Change the "bindingRedirect" tag for Microsoft.Owin, Microsoft.Owin.Security.OAuth, Microsoft.Owin.Security.Cookies, Microsoft.Owin.Security to as follows:

<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.1.0" />

this could work.

查看更多
神经病院院长
3楼-- · 2019-02-07 16:50

In my case, I have this error in code first during "update database". I put "Set a as startUp a Project" in project with migration.it helped me

查看更多
虎瘦雄心在
4楼-- · 2019-02-07 16:52

in my case, it turned out to be IIS express issue. Once i changed debug to Local IIS, error was gone.

查看更多
登录 后发表回答