Skip to content

System.Text.Json 10.x dependency breaks .NET Native toolchain compatibility #937

Description

@AlexisGross

Version

v6.5.7

Platform

UWP (Universal Windows Platform) with .NET Native Toolchain enabled (<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>)

Steps to reproduce

Steps to reproduce

  1. Create a new project using the "Blank App (Universal Windows) (.NET Native)" template.
    (Note: Do not use the standard "Blank App (Universal Windows)" template if it uses Modern .NET/Native AOT, as the issue is specific to the legacy .NET Native toolchain).
  2. Install YoutubeExplode version 6.5.7.
  3. Ensure the project is configured to use the .NET Native Toolchain.
    • In Visual Studio: Project Properties > Build > "Compile with .NET Native toolchain".
    • Or in .csproj: ensure <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain> is set (this is default for Release builds).
  4. Build the project in Release.
  5. Observed Result: The build fails with MCG0007 errors due to System.Text.Json 10.x.

Details

The recent update bumped the System.Text.Json polyfill for netstandard2.0 targets to version 10.0.2.

In the YoutubeExplode.csproj, the current logic is:

<PackageReference
  Include="System.Text.Json"
  Version="10.0.2"
  Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp3.0'))"
/>

Since UWP targets netstandard2.0 (and is NOT compatible with netcoreapp3.0), this condition evaluates to true, forcing the project to download and link System.Text.Json v10.x.

The Issue:
The .NET Native toolchain (MCG) used by UWP is stricter than modern Native AOT. The v10.x branch of System.Text.Json has drifted from the compatibility baseline required by the legacy .NET Native compiler. This causes compilation errors and runtime marshalling exceptions because the v10 binaries contain references (or trigger paths in dependencies) that the static compiler cannot resolve or deems unsafe for the AppContainer.

Proposed Solution

I suggest pinning the System.Text.Json reference to the 9.x (LTS) branch specifically for netstandard2.0 targets, as this is the intersection point for UWP and older Native AOT toolchains.

You can achieve this in two ways:

Option A: Simple Downgrade
Since netstandard2.0 is the primary legacy target in this project, simply reverting the version in the existing condition is the cleanest fix.

<PackageReference
  Include="System.Text.Json"
  Version="9.0.2"
  Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp3.0'))"
/>

Option B: Granular Configuration (If you want to keep v10 for .NET Framework)
If you prefer to keep System.Text.Json v10.x for other potential legacy targets (like .NET Framework 4.8), you can split the reference to target netstandard2.0 explicitly:

<PackageReference
  Include="System.Text.Json"
  Version="9.0.2"
  Condition="'$(TargetFramework)' == 'netstandard2.0'"
/>

<PackageReference
  Include="System.Text.Json"
  Version="10.0.2"
  Condition="'$(TargetFramework)' != 'netstandard2.0' And !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp3.0'))"
/>

By applying either of these changes, UWP consumers will be able to compile with the .NET Native toolchain again without breaking modern .NET consumers.

Checklist

  • I have looked through existing issues to make sure that this bug has not been reported before
  • I have provided a descriptive title for this issue
  • I have made sure that this bug is reproducible on the latest version of the package
  • I have provided all the information needed to reproduce this bug as efficiently as possible
  • I have sponsored this project
  • I have not read any of the above and just checked all the boxes to submit the issue

Activity

  1. Tyrrrz commented on Feb 15, 2026

    @Tyrrrz
    Owner

    Is this ultimately a bug in STJ or a fundamental incompatibility that excludes UWP forever going forward?

  2. AlexisGross commented on Feb 16, 2026

    @AlexisGross
    Author

    It looks like a fundamental incompatibility regarding the platform lifecycles rather than a bug in STJ itself.

    The UWP toolchain (.NET Native) is effectively in maintenance mode and relies on an older compiler stack (MCG) that hasn't been updated to support the modern IL patterns and optimizations that System.Text.Json v10 is adopting.

    Since Microsoft is unlikely to backport these modern runtime features to the legacy UWP compiler, pinning v9.x for netstandard2.0 targets is the safest architectural solution. This keeps the library functional for legacy consumers (UWP, older Xamarin/Unity) without holding back modern .NET features for the .net10.0 targets.

  3. Tyrrrz commented on Feb 16, 2026

    @Tyrrrz
    Owner

    Ok thanks for the information. I'll pin the version for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions