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条回答
放荡不羁爱自由
2楼-- · 2019-02-07 16:28

Renaming app.config to web.config works for me. Or just make a copy of app.config and call it web.config

查看更多
Animai°情兽
3楼-- · 2019-02-07 16:29

I took your idea, thanks for the research you did, and I did it like this:

get-project PerfSurf | Update-Package Microsoft.Owin.Security

It's much more simpler, and this will update manifest itself.

Ignore this (get-project PerfSurf) part, as I use it because I have multiple test project and don't want to update them all

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

Ok I've solved it.

I had to upgrade my Microsoft.Owin.Security package to 2.1.0 with this command

Install-Package Microsoft.Owin.Security -Version 2.1.0

And modify the bindings in my App.config like this

<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
查看更多
老娘就宠你
5楼-- · 2019-02-07 16:38

This assembly does not match what was requested that is why you get this error. check the Microsoft.Owin.Security version in the GAC. Also see here

查看更多
够拽才男人
6楼-- · 2019-02-07 16:41

In my case, I had two projects:

  • MyProj.MvcWeb (an MVC application that referenced Microsoft.Owin.Security 3.0.0)
  • MyProj.Data.Entities (a class library that referenced Microsoft.Owin.Security 2.1.0; not sure how this happened)

Upgrading Microsoft.Owin.Security from 2.1.0 to 3.0.0 in the MyProj.Data.Entities project fixed the issue for me.

查看更多
放我归山
7楼-- · 2019-02-07 16:45

I fixed it by changing my Web.config configuration tag:

from this:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

to this:

<configuration>

dont know why this works.

查看更多
登录 后发表回答