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

By

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

Step-by-Step Guide

Step 1: Determine If Your Project Is Affected

Most projects are not affected. You are safe if:

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:

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

Tags:

Related Articles

Recommended

Discover More

sodozbetsodo123b123b69vn8 Critical Lessons from the KICS and Trivy Supply Chain Attacks of 2026777loc777locLinux Kernel Paves Way for ASUS ROG RAIKIRI II Controller SupportKubernetes v1.36: Enhanced Controller Reliability with Staleness Mitigation and Observability69vnzbetApple to Pay $250 Million to Settle Lawsuit Over Delayed AI Siri FeaturesDolt's Prolly Trees: A Breakthrough in Version-Controlled Databases