2014-10-06 138 views
7

這裏有另一個類似於SignalR 2.0.2 and Owin 2.0.0 dependency conflict的問題時,Microsoft.Owin 2.0.2.0依賴衝突。如果我作爲控制檯應用程序運行項目,我很好。否則,類庫,如果我從命令提示符下運行它,我從IIS表達這種錯誤說:當我已經安裝3.0.0.0

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(應用程序);

任何想法?

回答

37

我只需要將App.config重命名爲Web.config或創建它的副本並將其命名爲Web.config即可。

+15

你應該選擇這個作爲答案。在與Scott Scott Allen的複數網站視頻「ASP.NET MVC 5 Fundamentals」合作時,我遇到了這個問題。他沒有提到這是讓KatanaIntro項目運作的一個步驟。也許它是一個新問題。 – Jordan 2015-01-29 16:14:02

+3

和喬丹一樣,這個效果很好。謝謝! – 2015-03-04 15:54:56

+3

當我和他一起編寫應用程序時,我在Scott Allen的Plural網站視頻中遇到了同樣的情況。感謝你的回答!! – 2015-08-05 21:17:43

-1

安裝Microsoft.Owin.Security包。這個對我有用。

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

+0

與我的回答有什麼不同嗎? – 2016-05-13 09:36:13

0

嘗試運行

cmd命令:

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

,並重新命名的AppConfig到WebConfig

0

轉到項目Refrences &找出Microsoft.Owin。 右鍵點擊它&檢查屬性的版本。

項目彙編版本&在webconfig下面的newVersion應該是相同的。

<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
相關問題