Version
v6.5.7
Platform
UWP (Universal Windows Platform) with .NET Native Toolchain enabled (<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>)
Steps to reproduce
Steps to reproduce
- 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).
- Install
YoutubeExplode version 6.5.7.
- 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).
- Build the project in Release.
- 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
Version
v6.5.7
Platform
UWP (Universal Windows Platform) with .NET Native Toolchain enabled (
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>)Steps to reproduce
Steps to reproduce
(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).
YoutubeExplodeversion 6.5.7..csproj: ensure<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>is set (this is default for Release builds).MCG0007errors due toSystem.Text.Json10.x.Details
The recent update bumped the
System.Text.Jsonpolyfill fornetstandard2.0targets to version 10.0.2.In the
YoutubeExplode.csproj, the current logic is:Since UWP targets
netstandard2.0(and is NOT compatible withnetcoreapp3.0), this condition evaluates totrue, forcing the project to download and linkSystem.Text.Jsonv10.x.The Issue:
The .NET Native toolchain (MCG) used by UWP is stricter than modern Native AOT. The v10.x branch of
System.Text.Jsonhas 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.Jsonreference to the 9.x (LTS) branch specifically fornetstandard2.0targets, 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.0is the primary legacy target in this project, simply reverting the version in the existing condition is the cleanest fix.Option B: Granular Configuration (If you want to keep v10 for .NET Framework)
If you prefer to keep
System.Text.Jsonv10.x for other potential legacy targets (like .NET Framework 4.8), you can split the reference to targetnetstandard2.0explicitly: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