Kousa4 Stack
ArticlesCategories
Reviews & Comparisons

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

Published 2026-05-05 02:44:13 · Reviews & Comparisons

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

  • .NET SDK version 11.0.100-preview.4 or later (or the corresponding Visual Studio 18.8 preview)
  • A test project that uses dotnet test or Test Explorer
  • Basic familiarity with NuGet package references and project files
  • Optional: a text editor or IDE to edit .csproj files

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:

  • Build errorCS0103: The name 'JObject' does not exist in the current context (or similar) indicating missing Newtonsoft.Json types.
  • Runtime errorSystem.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0'.
  • Extension load error – A test adapter or data collector fails to load with a FileNotFoundException for Newtonsoft.Json.

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

  • Always explicitly reference dependencies your code uses. Relying on transitive leaks from the test platform is fragile and not guaranteed in future versions.
  • Use the latest stable version of Newtonsoft.Json (currently 13.0.3) if you need it. Older versions are marked as vulnerable on NuGet.org.
  • Consider migrating to System.Text.Json if your project is on .NET Core 3.1 or later. It’s the native serializer and avoids adding an extra dependency.
  • Update your test adapters and data collectors to explicitly reference all their dependencies. This prevents issues when the host framework changes.
  • Review the official VSTest documentation for any additional migration guidance or breaking changes in the .NET 11 time frame.
  • Test your CI/CD pipelines with the updated SDK to catch any issues early before deploying to production.

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.