How to Handle the Removal of Newtonsoft.Json from VSTest in .NET 11 and Visual Studio 18.8

Introduction

Starting with .NET 11 Preview 4 and Visual Studio 18.8, the VSTest platform—which powers dotnet test and Test Explorer—will no longer depend on Newtonsoft.Json. Instead, it will use System.Text.Json on .NET and JSONite on .NET Framework. This security-driven change is part of removing vulnerable Newtonsoft.Json versions from the SDK. While most projects require no action, a few may encounter build or runtime errors. This guide walks you through identifying and fixing any issues.

How to Handle the Removal of Newtonsoft.Json from VSTest in .NET 11 and Visual Studio 18.8
Source: devblogs.microsoft.com

What You Need

  • A test project targeting .NET 11 Preview 4 or later, or using Visual Studio 18.8 or later
  • Basic understanding of NuGet package references in .csproj files
  • Access to a terminal or command prompt for running dotnet test
  • Optional: an editor to view and modify project files

Step-by-Step Guide

Step 1: Determine If Your Project Is Affected

Most projects are not affected. You are safe if:

  • Your test project does not use Newtonsoft.Json types (e.g., JObject, JsonConvert).
  • You have an explicit PackageReference to Newtonsoft.Json in your project file.
  • You use xUnit or NUnit on .NET, or rely on AppDomains (they already require an explicit reference).

To check: Search your codebase for using Newtonsoft.Json or JObject. Inspect your .csproj for any ExcludeAssets="runtime" on the Newtonsoft.Json package. If in doubt, run dotnet test under the new SDK to see errors.

Step 2: Fix Build Errors from Missing Reference

If your test project uses Newtonsoft.Json types but lacks a direct NuGet reference, it compiled before only because VSTest leaked the package. After the update, you will see a build error like:

CS0246: The type or namespace name 'Newtonsoft' could not be found

Fix: Add the following line to your .csproj inside an <ItemGroup>:

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Then restore and rebuild.

Step 3: Resolve Runtime FileNotFoundException

If you have a package reference that excludes runtime assets, for example:

<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
  <ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>

Previously, VSTest’s copy covered the missing runtime file. After removal, tests will fail with:

System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.

Fix: Remove the <ExcludeAssets>runtime</ExcludeAssets> line, or install Newtonsoft.Json without excluding runtime assets (i.e., use a normal PackageReference without ExcludeAssets). Then retest.

How to Handle the Removal of Newtonsoft.Json from VSTest in .NET 11 and Visual Studio 18.8
Source: devblogs.microsoft.com

Step 4: Handle Extension Load Errors in Test Adapters or Data Collectors

If you have a custom test adapter or data collector that uses Newtonsoft.Json but does not declare it as a dependency, it may fail to load. The error message will look like:

Data collector 'SampleDataCollector' threw an exception ... System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json'

Fix: Add a direct PackageReference to Newtonsoft.Json (version 13.0.3 or compatible) in the adapter/collector project. Ensure the package is included in the output directory. Rebuild and test.

Step 5: Validate Your Changes

After applying fixes, run your tests using dotnet test or from Test Explorer. Verify that:

  • All tests pass.
  • No warnings about missing or downgraded Newtonsoft.Json.
  • TRX reports or CI logs show no file-not-found errors.

If errors persist, double-check that the Newtonsoft.Json version you referenced matches the one originally expected (13.0.3 is safe). You can also clean and rebuild the solution.

Tips and Conclusions

  • Update early: Even if you are not on .NET 11 Preview 4 yet, adding explicit references now future-proofs your project.
  • Check CI/CD: After updating the SDK, monitor your build pipelines for failures – they may surface hidden dependencies.
  • No wire format change: The VSTest communication protocol remains unchanged, so older test hosts will still work.
  • Performance is equal or better: The switch to System.Text.Json or JSONite does not degrade serialization speed.
  • Common misassumption: If you never explicitly referenced Newtonsoft.Json, you likely do not need to add it – unless you used its types in test code.
  • Need help? Consult the Step 2 or Step 3 sections above for specific fixes.
Tags:

Recommended

Discover More

god88Smartwatch Heart Rate Data Could Revolutionize Depression Diagnosis, Experts Saytv88Python Security Response Team: Governance Updates and How to Get Involved8 Key Updates in SkiaSharp 4.0 Preview 1 That Transform .NET Graphicsgod88mf8bettv88How to Safeguard Sensitive Data in Load Tests with Grafana Cloud k6 Secrets Managementbay789How to Successfully Implement Dogfooding in Your Development Processku88mf8betku88bay789