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

时间:2014-10-06 14:34:35

标签: c# owin iis-express

这里有另一个类似于SignalR 2.0.2 and Owin 2.0.0 dependency conflict的问题。如果我将项目作为控制台应用程序运行我很好。否则,作为类库,如果我从命令提示符运行它,我从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(app);

时才有效

有什么想法吗?

4 个答案:

答案 0 :(得分:43)

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

答案 1 :(得分:0)

尝试运行

cmd命令:

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

并将Appconfig重命名为WebConfig

答案 2 :(得分:0)

转到项目参考&amp;找出Microsoft.Owin。 右键单击它&amp;检查属性上的版本。

项目组装版本&amp; webconfig以下的行newVersion应该是相同的。

 composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName tutorial-network

答案 3 :(得分:-1)

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

PS。别忘了重命名app.config文件。