ASP.NET self host error

620 Views Asked by At

I'm trying to get ASP.NET Web API self host running. I keep getting this error.

How do I resolve this?

Assuming assembly reference Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches assemblyMicrosoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. You may need to supply runtime policy (CS1701)

Here is my simple start up script.

static void Main(string[] args)
    {
        using (WebApp.Start<TestApi> ("http://*:9090/")) 
        {
            Console.WriteLine ("server started");
        }
    }
1

There are 1 best solutions below

2
On

The two assemblies differ in release and/or version number. For unification to occur, you must specify directives in the application's .config file, and you must provide the correct strong name of an assembly, as demonstrated in the following example code:

using System.Reflection;
[assembly:AssemblyVersion("1.0")]
public class A {
   public void M1() {}
}

OR:

Perhaps you need a binding redirect in your .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>