Repository navigation
Description
Summary
The .NET SDK currently ships the Newtonsoft.Json assembly in several locations within the SDK layout. We should remove this dependency from the SDK by eliminating project references that bring it in and migrating usages to System.Text.Json where possible.
Removing this dependency would reduce the SDK servicing surface area, decrease SDK size, and unblock work related to Native AOT.
Motivation
Security / Servicing
Bundling Newtonsoft.Json in the SDK introduces an additional dependency that must be monitored and serviced for potential security vulnerabilities.
Migrating to System.Text.Json reduces this servicing burden because it ships as part of the .NET platform and is already covered by the platform servicing model.
SDK Size Reduction
Removing Newtonsoft.Json would also help reduce the size of the SDK installation.
Historically the SDK contained multiple copies of this assembly. Deduplication work reduced this to two primary copies, but it still contributes unnecessary size to the SDK.
Related work:
Native AOT Compatibility
Usage of Newtonsoft.Json is a blocker for some Native AOT scenarios due to its heavy reliance on reflection and dynamic behavior. Migrating to System.Text.Json helps unblock this work.
Related work:
Current Locations in the SDK
The following instances of Newtonsoft.Json.dll currently appear in the SDK layout:
- ./DotnetTools/dotnet-user-secrets/11.0.0-preview.3.26152.106/tools/net11.0/any/Newtonsoft.Json.dll - Replace Newtonsoft.Json with System.Text.Json in dotnet-user-secrets aspnetcore#65686
- ./TestHostNetFramework/Newtonsoft.Json.dll
- ./Newtonsoft.Json.dll
- ./Sdks/Microsoft.NET.Sdk/tools/net472/Newtonsoft.Json.dll
- ./Sdks/Microsoft.NET.Sdk.Razor/tools/Newtonsoft.Json.dll - Convert Razor tools from NewtonSoft.Json to System.Text.Json #53345
Activity
MichaelSimons commentedon Mar 6, 2026
@DustinCampbell, @dotnet/razor-tooling - Regarding the /Microsoft.NET.Sdk.Razor reference, I noticed this code was refactored relatively recently in dotnet/dotnet@d24637c with the comment:
Does Razor have an interest in migrating their code to System.Text.Json to keep this code in sync? Ultimately, I am wondering if someone from Razor can help with migrating the Razor SDK from Newtonsoft.Json to System.Text.Json?
davidwengier commentedon Mar 6, 2026
@dbreshears FYI ^^^
MichaelSimons commentedon Mar 6, 2026
@nohwnd - Regarding the ./TestHostNetFramework/Newtonsoft.Json.dll reference, can you comment on the feasibility of migrating the Microsoft.TestPlatform.CLI from Newtonsoft.Json to System.Text.Json? I found microsoft/vstest#2488 which states it won't be implemented. If that is still the case, is the any path forward here?
nohwnd commentedon Mar 9, 2026
I would like to move it, but it is a potential breaking change, as customers probably depend on us shipping Newtonsoft.Json for them. I did investigate what it would take to move, but would need to spend more time on it to see if it is feasible technically (e.g. we annotate types with data attributes - and system.text.json does not support that, and I am not sure if that detail does not propagate to code that we don't control - hopefully not).
Will discuss it with my manager.
Are there any additional strong reason to drop newtonsoft.json? For me the strongest argument is the first one, security and servicing.
baronfel commentedon Mar 9, 2026
@nohwnd does the newtonsoft exposure also apply to
MTP-based test users? We're looking at AOT'ing the SLK/CLI overall, and part of that is trying to reduce/eliminate usage of dependencies that are not AOT-friendly.DustinCampbell commentedon Mar 9, 2026
I'm not working on Razor at the moment, so I can't speak to the team's capacity. However, getting rid of the Newtonsoft.Json dependency would definitely be fantastic.
nohwnd commentedon Mar 11, 2026
it does not, mtp uses system.text.json for .net , and embeds code of Jsonite for .NET Framework.
If there is drive towards NativeAOT then it would be good reason to drive change also into vstest.
davidwengier commentedon Mar 12, 2026
Razor bits are now using System.Text.Json