无法加载文件或程序集“Newtonsoft.Json”或其一个依赖项 清单定义与程序集引用不匹配

前端之家收集整理的这篇文章主要介绍了无法加载文件或程序集“Newtonsoft.Json”或其一个依赖项 清单定义与程序集引用不匹配前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
搜索后尝试的事情:

1)在Web.Config中放一个旧版本的绑定:@H_502_2@

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

2)编辑我的.csproj文件,以确保只有一个Newtonsoft参考@H_502_2@

<Reference Include="Newtonsoft.Json,Version=6.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed,processorArchitecture=MSIL">
   <HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
   <SpecificVersion>False</SpecificVersion>
   <Private>True</Private>
</Reference>

3)在我的电脑上搜索每个Newtonsoft.Json.dll并删除每个非6.0.1版本,并删除我的temp文件夹的内容@H_502_2@

4)在nuget管理器控制台中修复/重新安装软件包@H_502_2@

它成功的建设,但得到的错误,当去网站。@H_502_2@

编辑@H_502_2@

确定,所以然后我试图重新安装像每个nuget包,似乎已经添加了4.5版本的newtonsoft.json.dll,但我得到相同的错误。我的项目的目标freamework是.NET 4.5.1,这里是我现在得到的堆栈跟踪:@H_502_2@

Server Error in ‘/’ Application. @H_502_2@

Could not load file or assembly ‘Newtonsoft.Json’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)@H_502_2@

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. @H_502_2@

Exception Details: System.IO.FileLoadException: Could not load file or assembly ‘Newtonsoft.Json’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)@H_502_2@

Source Error: @H_502_2@

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.@H_502_2@

Assembly Load Trace: The following information can be helpful to determine why the assembly ‘Newtonsoft.Json’ could not be loaded.@H_502_2@

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Newtonsoft.Json | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name,version,culture,and public key token.
WRN: See whitepaper 07000 for more information and common solutions to this issue.
LOG: Appbase = file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/
LOG: Initial PrivatePath = c:\users\user\documents\visual studio 2013\Projects\foo\bar\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\foo\bar\web.config
LOG: Using host configuration file: C:\Users\user\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private,custom,partial,or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/bin/Newtonsoft.Json.DLL.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\foo\bar\web.config
LOG: Using host configuration file: C:\Users\user\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.5.0.0 redirected to 6.0.1.0.
LOG: Post-policy reference: Newtonsoft.Json,Version=6.0.1.0,PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.@H_502_2@

Stack Trace: @H_502_2@

[FileLoadException: Could not load file or assembly ‘Newtonsoft.Json’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]@H_502_2@

[FileLoadException: Could not load file or assembly ‘Newtonsoft.Json,PublicKeyToken=30ad4fe6b2a6aeed’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark& stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,RuntimeAssembly reqAssembly,Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective) +38@H_502_2@

[ConfigurationErrorsException: Could not load file or assembly ‘Newtonsoft.Json,PublicKeyToken=30ad4fe6b2a6aeed’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName,Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath,Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,IApplicationHost appHost,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,Exception appDomainCreationException) +516@H_502_2@

[HttpException (0x80004005): Could not load file or assembly ‘Newtonsoft.Json,PublicKeyToken=30ad4fe6b2a6aeed’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context) +254@H_502_2@

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408@H_502_2@

为了解决这个问题,我通过运行以下命令并检查结果确保我的所有项目使用相同的版本:
update-package Newtonsoft.Json -reinstall

最后,我从我的web.config中删除以下:@H_502_2@

<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>

如果你想确保所有的Newtonsoft.Json包是相同的版本,你可以这样指定版本:@H_502_2@

update-package Newtonsoft.Json -version 6.0.0 -reinstall

猜你在找的Json相关文章