Resharper Formatting: Align Equal Operands

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Manifest definition does not match the assembly reference

Ok, I think I got it to work now. I deleted every Newtonsoft.Json.dll on my machine that wasn't the latest version that I could find, made sure I had the latest version in NuGet, and build it and made sure that was the latest one in the bin folder, and I left the changes in the web.config and the .csproj. Now I'm on to another error, so it must be working..

Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0 issue using Google.Apis.*

This is usually bequase one of the other packages references Newton.JSON version 12.0.0.0
directly.(In this case probably the google apis packages)

As you add 13.0.1 to you project the other packages cant find the reference.

You can add the following bit to the 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-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<loadFromRemoteSources enabled="true" />
</runtime>

What this does is, when you code or one of the packages references a version of Newtonsoft.Json between version 0 and 13 it will now reference version 13

Can't use GitHttpClient from Powershell, Newtonsoft.Json version conflict

Preamble: the dependency resolution in the C# program was not picking up v12 where v9/6 was requested automagically; it was only doing so because the config file of the compiled program was telling it so, and that only happened once and because Newtonsoft v12 was being referenced in the project. Thanks to @n0rd for pointing that out. Resolving strongly named dependent assemblies to a higher major version is not a default behavior in .NET 4.5-8.

Modifying the config of Powershell to achieve the same might be possible, but I didn't go there. The original piece that needed this logic will be eventually running on servers that I don't control, so the less administrative overhead, the better. Now, for the working answer.


You can provide a resolve handler in Powershell 5 after all, telling .NET to use the loaded version of Newtonsoft in lieu of any other one. It goes like this:

$OnAssemblyResolve = [ResolveEventHandler] {
param($o, $e)
if($e.Name.StartsWith("Newtonsoft.Json,"))
{
return [AppDomain]::CurrentDomain.GetAssemblies() | ?{$_.FullName.StartsWith("Newtonsoft.Json,")}
}
return $null
}

Add-Type -Path "$APIPath\Newtonsoft.Json.dll"
[AppDomain]::CurrentDomain.add_AssemblyResolve($OnAssemblyResolve)
Add-Type -Path "$APIPath\Microsoft.TeamFoundation.SourceControl.WebApi.dll"
Add-Type -Path "$APIPath\Microsoft.VisualStudio.Services.WebApi.dll"
Add-Type -Path "$APIPath\System.Net.Http.Formatting.dll"
[AppDomain]::CurrentDomain.remove_AssemblyResolve($OnAssemblyResolve)

Once done loading Newtonsoft dependent assemblies (notably System.Net.Http.Formatting), remove the handler. Otherwise, it may interfere with Powershell's own functioning and cause a stack overflow exception, where an "assembly not found" condition within Powershell triggers the handler, which requires the same assembly to run, causing an endless recursion. In my case it happened downstream, when the script was trying to throw an unrelated exception, which required that System.Management.Automation.resources is loaded, which was not found, etc.


My previous statement that Powershell 5 couldn't hook .NET events with return values was wrong. I vaguely recall reading the docs for some event handling cmdlet, which mentioned that returning values from the handler block was not supported, guess that's where this misconception of mine came from.

Sharp Architecture - NewtonSoft.Json assembly mismatch

Issue:

The Newtonsoft.Json package was not updated due to the -Safe param added in the Sharp Architecture instructions

Solution:

  1. Manually update the NewtonSoft.Json package via the Package Manager Console:

    Update-Package Newtonsoft.Json

  2. Update the binding references for each project that includes that package via the Package Manager Console:

    Add-BindingRedirect

How can I fix assembly version conflicts with JSON.NET after updating NuGet package references in a new ASP.NET MVC 5 project?

Here the steps I used to fix the warning:

  • Unload project in VS
  • Edit .csproj file
  • Search for all references to Newtonsoft.Json assembly

    • Found two, one to v6 and one to v5
    • Replace the reference to v5 with v6
  • Reload project
  • Build and notice assembly reference failure
  • View References and see that there are now two to Newtonsoft.Json. Remove the one that's failing to resolve.
  • Rebuild - no warnings


Related Topics



Leave a reply



Submit