C# script component issues when using Newtonsoft.Json

We are noticing a problem with the C# scripting component since we rolled out Rhino 8 SR 22. The following script used to work before SR 22:

#r "nuget: Newtonsoft.Json"
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
if(json != null && json.Length > 0)
{
    try
    {
        JToken parsed = JToken.Parse(json);
        minifyJson = parsed.ToString(Formatting.None);
    }
    catch (Exception)
    {
        minifyJson = json;
    }
}

It’s throwing the following error now:

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

Update: this seems like an issue related to versioning of Newtonsoft.Json. I will update this thread once we found a solution. Please disregard the issue for now.

Found the reason for the problem:

When using #r "nuget: Newtonsoft.Json in the script component, the latest version of Newtonsoft.Json gets installed (currently 13.0.4). The script component uses this version for syntax checking. However, this version of the DLL isn’t used for running the script, because there is already another version of that DLL loaded, the one shipped with Rhino, which has a different version.

Updated script to output which DLL is being used:

#r "nuget: Newtonsoft.Json"
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
if(json != null && json.Length > 0)
{
    var ass = typeof(JObject).Assembly;
    assemblyInfo = ass;
    assemblyLocation = ass.Location;
    try
    {
        JToken parsed = JToken.Parse(json);
        minifyJson = parsed.ToString(Formatting.None, null);
    }
    catch (Exception)
    {
        minifyJson = json;
    }
}