2014-09-26 109 views
4

我做了一個在類庫中使用Json和ReshSharp Portable的簡單項目。NewtonSoft.Json程序集不匹配

Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 

的Newtonsoft.Json在庫(的NuGet),沒有扶養(即的NuGet說):

當我lanuch的應用程序,我總是有這樣的例外。 對於這些版本,一切正常,例外情況稱爲6.0.0.0,它就是在參考文件夾中的那個版本。

這是App.config中

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

這packages.config提前

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="FubarCoder.RestSharp.Portable" version="1.6.3" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" /> 
    <package id="Microsoft.Bcl" version="1.1.9" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" /> 
    <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" /> 
    <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" /> 
    <package id="Microsoft.Net.Http" version="2.2.28" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" /> 
    <package id="Newtonsoft.Json" version="6.0.5" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" /> 
</packages> 

感謝幫助我

編輯:我通過一個控制檯啓動這個類庫應用程序

This i s表示我使用新的app.config:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.5" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

NewtonSoft.Json的相關信息(上telerikJustDecompile):

[assembly: AssemblyCompany("Newtonsoft")] 
[assembly: AssemblyConfiguration("")] 
[assembly: AssemblyCopyright("Copyright © James Newton-King 2008")] 
[assembly: AssemblyDescription("Json.NET is a popular high-performance JSON framework for .NET")] 
[assembly: AssemblyFileVersion("6.0.5.17707")] 
[assembly: AssemblyProduct("Json.NET")] 
[assembly: AssemblyTitle("Json.NET Portable")] 
[assembly: AssemblyTrademark("")] 
[assembly: AssemblyVersion("6.0.0.0")] 
[assembly: CLSCompliant(true)] 
[assembly: CompilationRelaxations(8)] 
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] 
[assembly: InternalsVisibleTo("Newtonsoft.Json.Dynamic, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cbd8d53b9d7de30f1f1278f636ec462cf9c254991291e66ebb157a885638a517887633b898ccbcf0d5c5ff7be85a6abe9e765d0ac7cd33c68dac67e7e64530e8222101109f154ab14a941c490ac155cd1d4fcba0fabb49016b4ef28593b015cab5937da31172f03f67d09edda404b88a60023f062ae71d0b2e4438b74cc11dc9")] 
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")] 
[assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)] 
[assembly: TargetFramework(".NETPortable,Version=v4.5,Profile=Profile259", FrameworkDisplayName=".NET Portable Subset")] 

NewtonSoft.Json屬性(VS):

運行時版本:V4 .0.30319 版本:6.0.0.0

在的NuGet軟件包,Json.Net作爲參考版本6.0.5

+0

您的應用是便攜式應用還是常規應用? – Mrchief 2014-09-26 15:04:58

+0

另外,你是否看到從'packages \ Newtonsoft.Json.6.0.5 \ lib \ portable-win + net45 + MonoAndroid10 + MonoTouch10'位置引用的dll?它是否存在於包中? – Mrchief 2014-09-26 15:09:09

+0

@Mrchief:例外是在PCL中,但由控制檯應用程序 – clement 2014-09-26 15:11:10

回答

3

這種錯誤的一個常見原因是試圖在您沒有的版本中查找程序集的相關程序集。假設您使用ProjectXProjectX所需的Json.NET 6,並且您只有版本6.0.5。那會造成問題。您可以安裝所需版本或使用assemblyBinding

assemblyBinding允許您提供與請求版本不同的版本。請求的版本是oldVersion,服務版本是newVersion

試試這個:

<dependentAssembly> 
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.5" /> 
    </dependentAssembly> 

如果在上面的代碼中的數字不匹配,嘗試,直到它來調整他們。

+0

不錯的嘗試,但這不起作用,同一個地方的例外。謝謝 – clement 2014-09-26 15:00:03

+0

謝謝,但我又有同樣的例外(他們談論6.0.0) – clement 2014-09-26 15:04:11

+0

您能否確認您安裝的版本? – 2014-09-26 15:04:59

1

大解決我的問題:-) 說明: 首先找到其中Newtonsoft.Json的安裝版本(在package.config文件檢查)和舊版本應該是0.0.0.0-6.0.0.0和NEWVERSION =「您已安裝「

<dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.4" /> 
     </dependentAssembly> 
相關問題