当我安装了3.0.0.0时,Microsoft.Owin 2.0.2.0依赖项冲突

本文关键字:Owin 依赖 冲突 Microsoft 0时 安装 | 更新日期: 2023-09-27 18:25:39

这里是另一个类似SignalR 2.0.2和Owin 2.0.0依赖冲突的问题。如果我以控制台应用程序的身份运行该项目,我就可以了。否则,作为类库,如果我从命令提示符下运行它,我会从IIS Express中得到以下错误:

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)

但它不可能,因为我已经安装了3.0.0.0,在配置文件中我有:

            <?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>

这里是应用程序的其余部分:

            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!!!");
                        }
                    }
                }
            }

这里是来自命令提示符的指令:

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

忘了提一下,只有当我删除ConfigureWebApi(应用程序)时,它才有效;

有什么想法吗?

当我安装了3.0.0.0时,Microsoft.Owin 2.0.2.0依赖项冲突

我只需要将App.config重命名为Web.config,或者复制它并将其命名为Web.config即可。

转到项目Refracts&查找Microsoft.Owin。右键单击它&检查属性的版本。

项目程序集版本&webconfignewVersion的下一行应该是相同的。

<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />

尝试运行

cmd命令:

"%ProgramFiles%'IIS Express'iisexpress.exe" 
-path:"c:'Users'pci40'Documents'Visual Studio 2012'Projects'KatanaInfo
'KatanaInfo

并将Appconfig重命名为WebConfig

安装Microsoft.Owin.Security包。它对我有用。

PS。不要忘记重命名app.config文件。