搜索后我尝试过的事情:

in Web.Config put a binding on the old version: <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> Edit my .csproj file to make sure there is only one Newtonsoft reference <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> Search my computer for every Newtonsoft.Json.dll and delete every non 6.0.1 version and delete the contents of my temp folder Repair/Reinstall the package in nuget manager console

它成功构建,但在访问站点时得到错误。

EDIT

好吧,然后我尝试重新安装每个nuget包,它似乎已经添加了4.5版本的newtonsoft.json.dll,但我得到了同样的错误。我的项目的目标框架是。net 4.5.1,这里是我现在得到的堆栈跟踪:

Server Error in '/' Application. 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) 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. 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) Source Error: 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. Assembly Load Trace: The following information can be helpful to determine why the assembly Newtonsoft.Json could not be loaded.

=== 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 http://go.microsoft.com/fwlink/?LinkId=109270 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, Culture=neutral, 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.

堆栈跟踪:

[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)]

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)]
       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, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
       System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
       System.Reflection.Assembly.Load(String assemblyString) +28
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)]
       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

[HttpException (0x80004005): Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

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

当前回答

在确保我的计算机在所有位置都有相同的版本并且我的项目都指向相同的参考路径之后,我尝试了以下操作。我还确保旧版本的绑定是他们的,并绑定到我拥有的当前版本的dll。

我在一个有严格框架的环境中工作,框架团队经常用不同的dll来打乱版本控制。

我解决这个问题的方法是在visual studio(2013)中运行包管理器控制台。从那里我运行以下命令:

update-package Newtonsoft.Json -reinstall

紧随其后的是

update-package Newtonsoft.Json

这遍历并更新了我所有的配置文件和相关的项目文件。强制它们都到同一个dll版本。它最初是4.5版本,然后再次更新以获得最新版本。

其他回答

请注意,我有这个问题与桌面应用程序开发,而不是在WEB应用程序开发。 我在寻找解决方案时被重定向到这里,如果你也被重定向到这里,那么你可以使用GAC(全局程序集缓存),它用于将通用dll存储到全局以供使用。

我在医院的问题: 假设,我从C:\Documents通过CMD运行应用程序,并给定完整应用程序的路径D:\MyApp\MyApp.exe,其中使用Newtonsoft.json.dll和MyDLL.dll分别进行json和处理,它们存储在位置D:\MyApp\文件夹中。 现在,在执行时,它开始在C:\Users\Public中搜索DLL,其中没有DLL。然后,它给出错误,无法加载DLL Newtonsoft.json.dll。

所以我最终在GAC注册了dll。 可以通过两种方式安装

使用GACUTIL 您可以在“如何在GAC中注册.NET DLL文件”中找到步骤。

它很简单,但与Visual Studio安装一起安装。

如果GACUTIL不可用,请使用POWERSHELL

你可以关注Link, https://asvignesh.in/register-dll-in-gac-without-using-gacutil/

或使用哪个(链接页面描述与下方描述相同) Powershell命令:

PS C:\WINDOWS\system32> [System. reflection . assembly]::Load("System. reflection . assembly ")EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

PS C:\WINDOWS\system32> $publish = New-Object System.EnterpriseServices.Internal.Publish PS C:\WINDOWS\system32> $publish。GacInstall("dll path full");

希望你能找到答案。

在我的网页上把这部分注释掉。Config解决了我的问题:

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

但是当然,你需要确保你已经更新或你有正确的版本,在你的包管理器控制台中这样做:

update-package Newtonsoft.Json -reinstall

我遇到了这个问题,因为我有:项目A(一个桌面。exe)引用项目B(一个便携式。dll)。A和B有不同版本的JSON。Net,所以有一个加载器冲突。 一旦我让所有版本的JSON.net都一样,它就工作了。(这实际上是上面的一些解决方案正在做的事情-我只是呼吁为什么它有效)

我得到了dotnet核心同样的问题,并设法通过清除NuGet缓存来修复它。

打开powershell,输入以下命令。

dotnet nuget locals all --clear

然后我关闭Visual Studio,再次打开它,并在包管理器控制台输入以下命令:

Update-Package

NuGet现在应该恢复所有的包,并再次填充NuGet缓存。

在那之后,我能够在Linux容器中构建并启动我的dotnet核心webapi。

没有一个答案,包括选中的那个都不适合我。

解决办法要简单得多。我首先从BUS层删除了引用。然后从项目中删除dll(以确保它已经消失),然后重新安装JSON。NET从nuget包。而且,棘手的部分是,“把它关掉再打开”。

我刚刚重启visual studio,它工作了!

因此,如果您尝试了所有可能的方法,但仍然不能解决问题,请尝试关闭visual studio并再次打开,这可能会有所帮助。