391043 Stack
📖 Tutorial

VSTest Ends Dependency on Newtonsoft.Json: What You Need to Know

Last updated: 2026-05-05 09:10:22 Intermediate
Complete guide
Follow along with this comprehensive guide

Starting with .NET 11 Preview 4 and Visual Studio 18.8, VSTest—the engine behind dotnet test and Test Explorer—will no longer carry its long-standing dependency on Newtonsoft.Json. This change, driven by security and servicing reasons, replaces Newtonsoft.Json with System.Text.Json on .NET and JSONite on .NET Framework. While most test projects require no action, a small number may encounter build or runtime failures that can be resolved with straightforward package reference adjustments. Below are answers to common questions about this migration.

Why is VSTest removing its dependency on Newtonsoft.Json?

VSTest has shipped Newtonsoft.Json as part of the .NET SDK and Visual Studio for many years. All versions of Newtonsoft.Json below 13.0.0 are now flagged as vulnerable on NuGet.org. By carrying this dependency, the test platform remained exposed to future security advisories for a component it no longer requires. Removing Newtonsoft.Json is part of a broader initiative to eliminate the library from the .NET SDK entirely. This change is purely servicing and security-focused; it reduces the attack surface and simplifies dependency management without affecting functionality for the majority of users.

VSTest Ends Dependency on Newtonsoft.Json: What You Need to Know
Source: devblogs.microsoft.com

What changes are being made to the serialization libraries used by VSTest?

VSTest will now use System.Text.Json on .NET runtimes and JSONite on .NET Framework. Both are lightweight, built-in alternatives that eliminate the need for an external Newtonsoft.Json package. System.Text.Json is the modern, high-performance JSON library included in .NET Core/5+, while JSONite is a minimal JSON parser designed specifically for the .NET Framework test host. This switch does not alter the wire format—messages serialize identically regardless of which library is used—and it maintains or improves serialization performance.

Is the VSTest wire format or serialization behavior changing?

No, the wire format remains unchanged. Whether VSTest uses Newtonsoft.Json, System.Text.Json, or JSONite, the serialized messages are identical in structure and content. Older test hosts remain fully compatible with the updated platform, and vice versa. There is no need to modify test adapters or data collectors that rely on the standard VSTest protocol. Additionally, serialization performance is the same or slightly better with the new libraries, so no degradation should be observed in test execution speed.

Which test projects are NOT affected by this change?

Most test projects fall into the unaffected category. Specifically:

  • Projects that do not use Newtonsoft.Json at all.
  • Projects that already reference Newtonsoft.Json as a normal PackageReference (i.e., with runtime assets included).
  • xUnit and NUnit projects running on .NET or those using AppDomains, because they already required an explicit Newtonsoft.Json reference.

If your project does not rely on VSTest’s implicit copy of Newtonsoft.Json, you will see no errors and need no changes.

VSTest Ends Dependency on Newtonsoft.Json: What You Need to Know
Source: devblogs.microsoft.com

How can I fix a build error if my test project uses Newtonsoft.Json types but doesn't reference it?

If your test project uses Newtonsoft.Json types (such as JObject or JsonConvert) without a direct package reference, it previously compiled only because Newtonsoft.Json leaked through VSTest. After the update, this will cause a build error. The fix is simple: add an explicit package reference to Newtonsoft.Json in your test project file. For example:

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

This ensures your project owns the dependency and is not reliant on VSTest’s removed copy.

How do I resolve a runtime FileNotFoundException for Newtonsoft.Json after this update?

Some projects reference Newtonsoft.Json but exclude its runtime asset, for example:

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

These projects relied on VSTest’s copy of Newtonsoft.Json being present at test time. After the update, the test run will fail with a FileNotFoundException for the Newtonsoft.Json assembly. To fix this, remove the <ExcludeAssets>runtime</ExcludeAssets> element, or install Newtonsoft.Json without excluding runtime assets. This ensures the assembly is available during test execution.

What should test adapter or data collector authors do if they encounter extension load errors?

Test adapters and data collectors that used Newtonsoft.Json without declaring it as a dependency will fail at load time after the update. The error message will indicate a FileNotFoundException for Newtonsoft.Json. To fix this, authors must add an explicit dependency on Newtonsoft.Json (version 13.0.3 or later) in their extension project. If they prefer not to depend on Newtonsoft.Json, they can migrate their code to use System.Text.Json instead, which is already available on .NET. The key is to ensure the extension does not rely on VSTest’s previously provided copy.