錯誤信息如下:
錯誤 3 類型“Newtonsoft.Json.JsonPropertyAttribute”同時存在於“c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll”和“d:\project\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll”中 D:\project\p1\Hubs\TestHub.cs 35 10 p1
警告 1 無法解決“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”與“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”之間的沖突。正在隨意選擇“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”。 p1
警告 2 發現同一依賴程序集的不同版本間存在沖突。在 Visual Studio 中,請雙擊此警告(或選擇此警告並按 Enter)以修復沖突;否則,請將以下綁定重定向添加到應用程序配置文件中的“runtime”節點: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /></dependentAssembly></assemblyBinding> p1
這也許是json.net更新腳本的問題吧,也許以后就不會再出現這種錯誤了。
解決方法:
用記事本打開項目文件(*.csproj)
可以找到在這個文件中,有兩處Newtonsoft.Json的引用,刪掉老版本的引用就好了。
(上圖為更新后的引用,6.0.1版,此處保留)
(上圖為老版組件引用,沖突就是它引發的,截圖內容全部刪除)