Skip to content

Conversation

@jonpryor
Copy link
Contributor

Context: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
Context: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#specify-options

When building src/Uno.UI with trimmer warnings enabled (and turned up to 11):

dotnet build  src/Uno.UI/Uno.UI.Skia.csproj -bl \
  -p:TrimmerSingleWarn=false -p:_ExtraTrimmerArgs=--verbose -p:IsTrimmable=true -p:IsAotCompatible=true

Many of the warnings are around System.Text.Json usage:

…/src/Uno.UI/UI/Xaml/FontManifestHelpers.cs(34,6): error IL2026:
  Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(Stream, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code.
  JSON serialization and deserialization might require types that cannot be statically analyzed.
  Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Update JsonSerializer.Deserialize<TValue>() usage to remove the IL2026 warnings.

Specifically, update CoreWebView2WebMessageReceivedEventArgs.cs to use JsonSerializer.Deserialize<string>(string, JsonTypeInfo<string>), providing a JsonTypeInfo<string> derived from a
JsonSerializerOptions instance that only supports strings.

Update FontManifest*.cs to use
JsonSourceGenerationOptionsAttribute so that System.Text.Json source generation can generate an appropriate JsonSerializerOptions. This allows us to use
JsonSerializer.Deserialize<FontManifest>(Stream, JsonSerializerContext).

GitHub Issue: closes #

PR Type:

What is the current behavior? 🤔

What is the new behavior? 🚀

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21722/docs/index.html

@jonpryor jonpryor force-pushed the dev/jonpryor/jonp-Uno.UI-JSON-il2026 branch from c11457d to 623fbf2 Compare October 31, 2025 16:29
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21722/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21722/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 180507 has failed on Uno.UI - CI.

Context: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
Context: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#specify-options

When building `src/Uno.UI` with trimmer warnings enabled (and turned up to 11):

	dotnet build  src/Uno.UI/Uno.UI.Skia.csproj -bl \
	  -p:TrimmerSingleWarn=false -p:_ExtraTrimmerArgs=--verbose -p:IsTrimmable=true -p:IsAotCompatible=true

Many of the warnings are around System.Text.Json usage:

	…/src/Uno.UI/UI/Xaml/FontManifestHelpers.cs(34,6): error IL2026:
	  Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(Stream, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code.
	  JSON serialization and deserialization might require types that cannot be statically analyzed.
	  Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.

Update `JsonSerializer.Deserialize<TValue>()` usage to remove the
IL2026 warnings.

Specifically, update `CoreWebView2WebMessageReceivedEventArgs.cs` to
use `JsonSerializer.Deserialize<string>(string, JsonTypeInfo<string>)`,
providing a `JsonTypeInfo<string>` derived from a
`JsonSerializerOptions` instance that only supports strings.

Update `FontManifest*.cs` to use
[`JsonSourceGenerationOptionsAttribute`][0] so that System.Text.Json
source generation can generate an appropriate `JsonSerializerOptions`.
This allows us to use
`JsonSerializer.Deserialize<FontManifest>(Stream, JsonSerializerContext)`.

[0]: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonsourcegenerationoptionsattribute?view=net-9.0
@jonpryor jonpryor force-pushed the dev/jonpryor/jonp-Uno.UI-JSON-il2026 branch from 623fbf2 to 517e860 Compare November 3, 2025 18:37
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21722/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21722/docs/index.html

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants