How to Handle the Removal of Newtonsoft.Json from VSTest in .NET 11 and Visual Studio 18.8
By ⚡ min read
<h2>Introduction</h2>
<p>Starting with <strong>.NET 11 Preview 4</strong> and <strong>Visual Studio 18.8</strong>, the VSTest platform—which powers <code>dotnet test</code> and Test Explorer—no longer ships its own copy of <em>Newtonsoft.Json</em>. Instead, it uses <strong>System.Text.Json</strong> on .NET and <strong>JSONite</strong> 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.</p><figure style="margin:20px 0"><img src="https://devblogs.microsoft.com/dotnet/wp-content/uploads/sites/10/2026/04/vs-test-is-removing-its-newtonsoft-json-dependency.webp" alt="How to Handle the Removal of Newtonsoft.Json from VSTest in .NET 11 and Visual Studio 18.8" style="width:100%;height:auto;border-radius:8px" loading="lazy"><figcaption style="font-size:12px;color:#666;margin-top:5px">Source: devblogs.microsoft.com</figcaption></figure>
<h2>What You Need</h2>
<ul>
<li><strong>.NET SDK</strong> version 11.0.100-preview.4 or later (or the corresponding Visual Studio 18.8 preview)</li>
<li>A test project that uses <code>dotnet test</code> or Test Explorer</li>
<li>Basic familiarity with NuGet package references and project files</li>
<li>Optional: a text editor or IDE to edit <code>.csproj</code> files</li>
</ul>
<h2>Step-by-Step Guide</h2>
<h3 id="step1">Step 1: Detect Whether Your Project Is Affected</h3>
<p>After upgrading, run your tests. Look for one of these three error types:</p>
<ul>
<li><strong>Build error</strong> – <em>CS0103: The name 'JObject' does not exist in the current context</em> (or similar) indicating missing <em>Newtonsoft.Json</em> types.</li>
<li><strong>Runtime error</strong> – <em>System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0'</em>.</li>
<li><strong>Extension load error</strong> – A test adapter or data collector fails to load with a <em>FileNotFoundException</em> for <em>Newtonsoft.Json</em>.</li>
</ul>
<p>If you see none of these, your project is likely unaffected. Continue to <a href="#step5">Step 5</a> to verify.</p>
<h3 id="step2">Step 2: Fix a Build Error – Missing Newtonsoft.Json Reference</h3>
<p>If your test project directly uses <em>Newtonsoft.Json</em> types (like <code>JObject</code>, <code>JsonConvert</code>) but did not explicitly reference the NuGet package, it compiled before only because VSTest provided it transitively. Now you must add an explicit reference.</p>
<ol>
<li>Open your <code>.csproj</code> file in a text editor.</li>
<li>Inside an existing <code><ItemGroup></code>, add the following <code>PackageReference</code> (you can adjust the version to the latest stable):<br />
<pre><code><PackageReference Include="Newtonsoft.Json" Version="13.0.3" /></code></pre>
</li>
<li>Save the file and rebuild the project.</li>
</ol>
<p>If you prefer using the NuGet Package Manager in Visual Studio, search for <strong>Newtonsoft.Json</strong> (version 13.0.3 or later) and install it into your test project.</p>
<h3 id="step3">Step 3: Fix a Runtime Error – FileNotFoundException Due to Excluded Runtime Assets</h3>
<p>Some projects reference <em>Newtonsoft.Json</em> but exclude its runtime assets using <code><ExcludeAssets>runtime</ExcludeAssets></code>. These projects previously depended on VSTest’s copy to load at runtime. With that copy removed, the test run fails.</p>
<ol>
<li>Locate the <code>PackageReference</code> for <em>Newtonsoft.Json</em> in your <code>.csproj</code> file.</li>
<li>If it contains an <code><ExcludeAssets>runtime</ExcludeAssets></code> element, <strong>either</strong>:<br />
<ul>
<li>Remove that entire element, or</li>
<li>Change <code>ExcludeAssets</code> to <code>All</code> (not recommended if you actually need the library at runtime) or simply remove the exclusion line.</li>
</ul>
</li>
<li>Save the file and rebuild.</li>
</ol>
<p>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.</p><figure style="margin:20px 0"><img src="https://uhf.microsoft.com/images/microsoft/RE1Mu3b.png" alt="How to Handle the Removal of Newtonsoft.Json from VSTest in .NET 11 and Visual Studio 18.8" style="width:100%;height:auto;border-radius:8px" loading="lazy"><figcaption style="font-size:12px;color:#666;margin-top:5px">Source: devblogs.microsoft.com</figcaption></figure>
<h3 id="step4">Step 4: Fix an Extension Load Error – Missing Dependency in a Test Adapter or Data Collector</h3>
<p>If you have a custom test adapter or data collector that internally uses <em>Newtonsoft.Json</em> but never declared it as a dependency, the extension will fail to load when VSTest no longer provides the assembly.</p>
<ol>
<li>Open the project file for your test adapter or data collector (<code>.csproj</code>).</li>
<li>Add a <code>PackageReference</code> for <em>Newtonsoft.Json</em> with a suitable version (e.g., 13.0.3).</li>
<li>Ensure the package’s assets are included (default is fine).</li>
<li>Rebuild and redeploy the extension.</li>
</ol>
<p>If you are using a third-party adapter that is not yours, contact the vendor for an updated version that declares its dependency properly.</p>
<h3 id="step5">Step 5: Verify the Fix</h3>
<ol>
<li>Run <code>dotnet test</code> from the command line, or open Test Explorer in Visual Studio and run all tests.</li>
<li>Confirm that no build errors, runtime errors, or extension failures appear.</li>
<li>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).</li>
<li>Also ensure that your test project does not have multiple conflicting versions of <em>Newtonsoft.Json</em>. Use the <code>dotnet list package --vulnerable</code> command to check for known vulnerabilities.</li>
</ol>
<h2>Tips and Best Practices</h2>
<ul>
<li><strong>Always explicitly reference dependencies</strong> your code uses. Relying on transitive leaks from the test platform is fragile and not guaranteed in future versions.</li>
<li><strong>Use the latest stable version</strong> of <em>Newtonsoft.Json</em> (currently 13.0.3) if you need it. Older versions are marked as vulnerable on NuGet.org.</li>
<li><strong>Consider migrating to <em>System.Text.Json</em></strong> if your project is on .NET Core 3.1 or later. It’s the native serializer and avoids adding an extra dependency.</li>
<li><strong>Update your test adapters and data collectors</strong> to explicitly reference all their dependencies. This prevents issues when the host framework changes.</li>
<li><strong>Review the official VSTest documentation</strong> for any additional migration guidance or breaking changes in the .NET 11 time frame.</li>
<li><strong>Test your CI/CD pipelines</strong> with the updated SDK to catch any issues early before deploying to production.</li>
</ul>
<p>By following these steps, you can ensure your test projects remain healthy after the removal of <em>Newtonsoft.Json</em> from VSTest. The change itself is transparent for the vast majority of users, and the fixes for those affected are straightforward.</p>