這裏有另一個類似於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(應用程序);
任何想法?
你應該選擇這個作爲答案。在與Scott Scott Allen的複數網站視頻「ASP.NET MVC 5 Fundamentals」合作時,我遇到了這個問題。他沒有提到這是讓KatanaIntro項目運作的一個步驟。也許它是一個新問題。 – Jordan 2015-01-29 16:14:02
和喬丹一樣,這個效果很好。謝謝! – 2015-03-04 15:54:56
當我和他一起編寫應用程序時,我在Scott Allen的Plural網站視頻中遇到了同樣的情況。感謝你的回答!! – 2015-08-05 21:17:43