Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.Owin 2.0.2.0 dependency conflict when I have installed 3.0.0.0

here another question similar to SignalR 2.0.2 and Owin 2.0.0 dependency conflict. If I run the project as Console Application I'm fine. Otherwise, as class library if I run it from command prompt I got this error from IIS Express saying:

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

But it cannot be, as I have installed 3.0.0.0 and in the config file I have:

            <?xml version="1.0" encoding="utf-8"?>
        <configuration>
            <startup> 
                <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
            </startup>
          <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
              <dependentAssembly>
                <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
              </dependentAssembly>
            </assemblyBinding>
          </runtime>
        </configuration>

Here the rest of the application:

            namespace katanaIntro
            {
                using AppFunc = Func<IDictionary<string, object>, Task>;

                public class Startup
                {
                    public void Configuration(IAppBuilder app)
                    {
                        app.Use(async (environment, next) =>
                        {
                            Console.WriteLine("Requestion : " + environment.Request.Path);
                            await next();
                            Console.WriteLine("Response : " + environment.Response.StatusCode);
                        });
                        ConfigureWebApi(app);
                        app.UseHelloWorld();
                    }

                    private void ConfigureWebApi(IAppBuilder app)
                    {
                        var config = new HttpConfiguration();
                        config.Routes.MapHttpRoute(
                            "DefaultApi",
                            "api/{controller}/{id}",
                            new { id = RouteParameter.Optional });
                        app.UseWebApi(config); // <-- It works without this!!!
                    }
                }

                public static class AppBuilderExtensions
                {
                    public static void UseHelloWorld(this IAppBuilder app)
                    {
                        app.Use<HelloWorldComponent>();
                    }
                }

                public class HelloWorldComponent
                {
                    AppFunc _next;

                    public HelloWorldComponent(AppFunc next)
                    {
                        _next = next;
                    }

                    public Task Invoke(IDictionary<string, object> environment)
                    {
                        var response = environment["owin.ResponseBody"] as Stream;
                        using (var writer = new StreamWriter(response))
                        {
                            return writer.WriteAsync("Hello!!!");
                        }
                    }
                }
            }

Here the instruction from command prompt:

     "c:\Program Files\IIS Express\iisexpress.exe" /path:"C:\Users\smagistri\Projects\Lab 4.5\katanaIntro\katanaIntro"

Forgot to mention that it works only if I remove the ConfigureWebApi(app);

Any ideas?

like image 805
Stefano Magistri Avatar asked Oct 06 '14 14:10

Stefano Magistri


2 Answers

Go to project Refrences & find out Microsoft.Owin. Right click on it & check the version on properties.

Project Assembly version & below line of webconfig newVersion should be same.

<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
like image 60
Avinash Singh Avatar answered Oct 23 '22 14:10

Avinash Singh


I only need to rename the App.config to Web.config or make a copy of it and name it Web.config and it works.

like image 42
Stefano Magistri Avatar answered Oct 23 '22 13:10

Stefano Magistri