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—no longer ships its own copy of Newtonsoft.Json. Instead, it uses System.Text.Json on .NET and JSONite on .NET Framework. This change is part of a broader security and servicing effort to reduce dependencies on outdated components. While most test projects will work without any modifications, a small number may encounter build or runtime errors. This guide will help you identify and fix these issues quickly.

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: Detect Whether Your Project Is Affected

After upgrading, run your tests. Look for one of these three error types:

If you see none of these, your project is likely unaffected. Continue to Step 5 to verify.

Step 2: Fix a Build Error – Missing Newtonsoft.Json Reference

If your test project directly uses Newtonsoft.Json types (like JObject, JsonConvert) but did not explicitly reference the NuGet package, it compiled before only because VSTest provided it transitively. Now you must add an explicit reference.

  1. Open your .csproj file in a text editor.
  2. Inside an existing <ItemGroup>, add the following PackageReference (you can adjust the version to the latest stable):
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  3. Save the file and rebuild the project.

If you prefer using the NuGet Package Manager in Visual Studio, search for Newtonsoft.Json (version 13.0.3 or later) and install it into your test project.

Step 3: Fix a Runtime Error – FileNotFoundException Due to Excluded Runtime Assets

Some projects reference Newtonsoft.Json but exclude its runtime assets using <ExcludeAssets>runtime</ExcludeAssets>. These projects previously depended on VSTest’s copy to load at runtime. With that copy removed, the test run fails.

  1. Locate the PackageReference for Newtonsoft.Json in your .csproj file.
  2. If it contains an <ExcludeAssets>runtime</ExcludeAssets> element, either:
    • Remove that entire element, or
    • Change ExcludeAssets to All (not recommended if you actually need the library at runtime) or simply remove the exclusion line.
  3. Save the file and rebuild.

Alternatively, if you had a valid reason to exclude runtime assets (e.g., you only used the package for compile-time types), consider installing a different package that doesn’t require runtime loading.

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

Step 4: Fix an Extension Load Error – Missing Dependency in a Test Adapter or Data Collector

If you have a custom test adapter or data collector that internally uses Newtonsoft.Json but never declared it as a dependency, the extension will fail to load when VSTest no longer provides the assembly.

  1. Open the project file for your test adapter or data collector (.csproj).
  2. Add a PackageReference for Newtonsoft.Json with a suitable version (e.g., 13.0.3).
  3. Ensure the package’s assets are included (default is fine).
  4. Rebuild and redeploy the extension.

If you are using a third-party adapter that is not yours, contact the vendor for an updated version that declares its dependency properly.

Step 5: Verify the Fix

  1. Run dotnet test from the command line, or open Test Explorer in Visual Studio and run all tests.
  2. Confirm that no build errors, runtime errors, or extension failures appear.
  3. If problems persist, double-check that you have added the correct package reference and that you are using a compatible version (13.0.3 or later is recommended).
  4. Also ensure that your test project does not have multiple conflicting versions of Newtonsoft.Json. Use the dotnet list package --vulnerable command to check for known vulnerabilities.

Tips and Best Practices

By following these steps, you can ensure your test projects remain healthy after the removal of Newtonsoft.Json from VSTest. The change itself is transparent for the vast majority of users, and the fixes for those affected are straightforward.

Related Articles

Recommended

Discover More

How to Harness xAI’s Grok 4.3: A Step-by-Step Guide to Accessing the New API and Voice Cloning ToolsStealthy 'DEEP#DOOR' Python Backdoor Targets Browser and Cloud Credentials via Tunneling ServiceWhy Motorola’s New Razr+ Isn’t Worth the Upgrade – Save Big with the 2025 ModelApple Rushes to Supreme Court to Halt App Store Fee Ruling Amid Epic Games FightSecuring Your Autonomous AI Agent: A Practical Guide to Safely Deploying Tools Like OpenClaw