2016-09-30 113 views
1

我得到的錯誤:衝突Newtonsoft.Json DLL版本signalR +的WebAPI

無法加載文件或程序集「Newtonsoft.Json」或它 的一個依賴。清單定義與裝配 參考不匹配。

將WebApi控制器類添加到我的ASP.NET MVC項目後。我的項目中也有SignalR。兩者都使用Newtonsoft.Json,但似乎它們沒有引用相同的版本。

SignalR使用,並與6.0.8版本的作品,而錯誤告訴我,MapHttpRoute:

protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
     RouteConfig.RegisterRoutes(RouteTable.Routes); 
     BundleConfig.RegisterBundles(BundleTable.Bundles); 
     RouteTable.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); 
    } 

嘗試加載4.5版本。

我看到這篇文章SignalR & WebApi - colliding Newtonsoft.Json references

,但我不知道怎麼告訴的WebAPI對6.0.8版本點。

+0

鏈接的問題是*很老*並不適用。添加相關的NuGet包,而不是添加對組件的引用。 NuGet將在您安裝軟件包時解決所有衝突 –

+0

當您說添加相關的NuGet軟件包時,是指通過NuGet安裝Newtonsoft.Json?因爲我已經試過了這個版本,並且用版本9.0.0更新了它,並且SignalR和WebApi都崩潰了,因爲它們找不到組件 – Morgan

+0

Json.NET和SignalR。 SignalR本身是另一個NuGet包。首先嚐試一個乾淨的項目,否則你將不得不刪除任何你已經添加到app.config中的重定向 –

回答

1

您可以使用AssemblyBinding重定向到您安裝的Newtonsoft.Json程序集。就在你的web.config添加

</configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.8" newVersion="6.0.8" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

這將錯誤的版本所有呼叫重定向到您的安裝版本6.0.8

+0

不幸的是,它已經是這種情況 – Morgan

+0

你試過這個[http://stackoverflow.com/a/12011221/6666799](http://stackoverflow.com/a/12011221/6666799) – Rabban

+0

不起作用,(配置中沒有命名空間,沒有有效路徑等) – Morgan