Navigating the Deprecation of Newtonsoft.Json in VSTest

By

Overview

Starting with .NET 11 Preview 4 and Visual Studio 18.8, the VSTest platform—the engine behind dotnet test and Test Explorer—no longer ships with Newtonsoft.Json. Instead, it uses System.Text.Json on .NET and JSONite on .NET Framework. This change is driven by security and servicing concerns: older versions of Newtonsoft.Json (below 13.0.0) are flagged as vulnerable on NuGet.org, and the dependency was unnecessary for VSTest itself. Removing it aligns with the broader .NET SDK cleanup. The wire format remains identical, older test hosts stay compatible, and serialization performance is equal or better. Most projects need no changes, but a small subset will encounter clear build or runtime failures. This guide explains everything you need to know to prepare and fix those issues.

Navigating the Deprecation of Newtonsoft.Json in VSTest
Source: devblogs.microsoft.com

Prerequisites

Before diving into the steps, ensure you have the following:

Step-by-Step Instructions

1. Identify if Your Project Is Affected

First, determine whether your test project falls into the affected category. The majority of projects are not affected:

Action: Inspect each test project’s .csproj for any PackageReference to Newtonsoft.Json. If absent but your code uses Newtonsoft.Json, you’re implicitly dependent. Also check for <ExcludeAssets>runtime</ExcludeAssets> in any Newtonsoft.Json reference.

2. Fix Missing References (Build Errors)

If a test project uses Newtonsoft.Json types without a direct package reference, the build will now fail with an error like: The type or namespace name 'Newtonsoft' could not be found. This previously compiled because VSTest’s copy leaked into the test project.

Fix: Add an explicit PackageReference for Newtonsoft.Json. Use the latest stable version (13.0.3 as of writing) to avoid future advisories:

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

Place this inside an <ItemGroup> in your .csproj. Rebuild the project to confirm the error disappears.

3. Fix Runtime Errors (FileNotFoundException)

Projects that reference Newtonsoft.Json but exclude its runtime assets (e.g., with <ExcludeAssets>runtime</ExcludeAssets>) previously relied on VSTest’s copy during test execution. After the update, the test run will throw:

System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, ...'

Fix: Remove the <ExcludeAssets>runtime</ExcludeAssets> from the package reference. If you must exclude assets for some other reason, ensure you include the runtime asset for Newtonsoft.Json. The simplest resolution is to change the reference to a standard one:

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

If you have other assets excluded (like compile), adjust carefully. After the change, rebuild and rerun your tests. The FileNotFoundException should be gone.

Navigating the Deprecation of Newtonsoft.Json in VSTest
Source: devblogs.microsoft.com

4. Fix Test Adapter or Data Collector Extension Errors

Custom test adapters or data collectors that used Newtonsoft.Json without declaring it as a dependency will now fail at load time. The error message looks like:

Data collector 'SampleDataCollector' threw an exception during type loading, construction, or initialization: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, ...'

Fix: Locate the adapter or data collector project and add a direct dependency on Newtonsoft.Json. For example, in its .csproj:

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

If the adapter is delivered as a NuGet package, you may need to update the package to include this dependency explicitly. Alternatively, if the adapter targets .NET Framework, consider switching to JSONite (which VSTest uses on .NET Framework) to avoid Newtonsoft.Json entirely—but that’s an advanced change. The immediate fix is to add the reference. Rebuild and redeploy the adapter, then test.

Common Mistakes

Summary

The removal of Newtonsoft.Json from VSTest is a proactive security measure that affects only projects that implicitly relied on the package being present via the test host. The fixes are straightforward: add a direct PackageReference to Newtonsoft.Json 13.0.3 if you use its types, remove any <ExcludeAssets>runtime</ExcludeAssets> from existing references, and ensure custom adapters declare their dependencies. By following the steps in this guide, you can upgrade to .NET 11 Preview 4+ or Visual Studio 18.8+ without disruption. For most teams, this is a quick one-line change—or no change at all.

Related Articles

Recommended

Discover More

10 Key Milestones in Intel Lunar Lake CPU Performance on Linux (2025-2026)Lenovo Yoga Slim 7i Aura Edition (2026) Breaks Cover: Stunning OLED Display, Featherlight Build, and Record Battery Life10 Essential Facts About AWS Interconnect: Simplifying Multicloud and Last-Mile ConnectivityUpgrade to Fedora Linux 44 on Silverblue: Your Complete Q&A GuideHow the FPGA Revolutionized Hardware Flexibility: A Guide to Reconfigurable Computing