Skip to content

JObject.ToString MissingMethodException when app built against Newtonsoft.Json 13.0.4 loads 13.0.3 from GAC #3084

@nicholas-renaud

Description

@nicholas-renaud

Applications compiled against Newtonsoft.Json 13.0.4 can fail at runtime if version 13.0.3 is installed in the Global Assembly Cache (GAC).

Because both 13.0.3 and 13.0.4 use AssemblyVersion = 13.0.0.0, the CLR will load the 13.0.3 assembly from the GAC even when the application was compiled against 13.0.4. This results in missing members at runtime.


Steps to Reproduce

  1. Install Newtonsoft.Json 13.0.3 into the GAC:
    gacutil /i Newtonsoft.Json.dll (13.0.3)
  2. Create a project that references NuGet package Newtonsoft.Json 13.0.4.
  3. Use the following code:
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    
    var jObject = JObject.Parse("{'fieldName':{'fieldValue':'innerObjectValue'},'anotherField':'anotherValue'}");
    jObject.ToString(Formatting.None);
  4. Build and run the project on the machine with 13.0.3 in the GAC.

Expected Behavior

The application should load the version it was compiled against (13.0.4) and successfully invoke the ToString overload.


Actual Behavior

The runtime loads Newtonsoft.Json 13.0.3 from the GAC, and the following exception occurs:

System.MissingMethodException : Method not found: 
'System.String Newtonsoft.Json.Linq.JToken.ToString(Newtonsoft.Json.Formatting)'

Notes

  • The issue is triggered by the fact that the AssemblyVersion remains 13.0.0.0 across these patch releases.
  • Since the GAC version takes precedence, applications compiled against 13.0.4 cannot safely run when 13.0.3 is present in the GAC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions