Skip to content

Conversation

@jonpryor
Copy link
Contributor

@jonpryor jonpryor commented Dec 31, 2025

When building uno.chefs for NativeAOT with all warnings enabled:

dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \
  -bl Chefs/Chefs.csproj -p:UseSkiaRendering=true -p:SelfContained=true \
  -p:PublishAot=true -p:IsAotCompatible=true -p:TrimmerSingleWarn=false -p:_ExtraTrimmerArgs=--verbose \
  -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \
  -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen

We observe the following warnings (among others):

AOT analysis warning IL3050:
  Uno.Xaml.Schema.XamlTypeName.XamlTypeName(XamlType): Using member 'System.Linq.Queryable.AsQueryable<XamlType>(IEnumerable`1<XamlType>)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
  Enumerating in-memory collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime.
  This may not work when AOT compiling.
AOT analysis warning IL3050: Uno.Xaml.XamlSchemaContext.ResolveXamlTypeName(String,String,IList`1<XamlType>): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
  The native code for this instantiation might not be available at runtime.

At a glance, XamlTypeName is an easy enough fix: don't use
.AsQueryable(). @jonpryor doesn't see any need for it here.

XamlSchemaContext.ResolveXamlTypeName() looks similarly easy:
just add [UnconditionalSuppressMessage], as is already done
elsewhere within Uno.Xaml.dll.

Additional thinking occurs: shouldn't this assembly be marked
as $(IsAotCompatible)=true? Try that, and:

/usr/local/share/dotnet/sdk/10.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(120,5): warning NETSDK1210:
  IsAotCompatible and EnableAotAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:
  <IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>

At which point everything becomes much more complicated:
Uno.Xaml.csproj targets netstandard2.0. When we multitarget both
netstandard2.0 and net10.0, everything breaks.
Because The World Has Moved On:

src/SourceGenerators/System.Xaml/System.Xaml/XamlException.cs(78,24): error CS0672: Member 'XamlException.GetObjectData(SerializationInfo, StreamingContext)' overrides obsolete member 'Exception.GetObjectData(SerializationInfo, StreamingContext)'. …
src/SourceGenerators/System.Xaml/System.Xaml/XamlException.cs(66,4): error SYSLIB0051: 'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.'
src/SourceGenerators/System.Xaml/System.Xaml/ParsedMarkupExtensionInfo.cs(153,31): error CA1865: Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char
…

Explore this a bit, but ultimately come to the conclusion that it
isn't worthwhile:

  1. Uno.Xaml.dll needs to maintain netstandard2.0 compatibility,
    as it's refernced by source generators.

  2. Multitargeting .NET 10 just adds "noise".

  3. Attempting to fix warnings introduced by $(IsAotCompatible)=true
    is a fools errand: everything eventually hits various forms
    of Reflection such as Type.MakeGenericType() and/or
    TypeDescriptor.GetConverter(), meaning everything needs to be
    marked with [RequiresDynamicCode] and
    [RequiresUnreferencedCode]. Other than introducing lots of
    warnings in referencing code, how does this benefit us?

    (It doesn't.)

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 ℹ️

@github-actions github-actions bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label Dec 31, 2025
@jonpryor jonpryor force-pushed the dev/jonpryor/jonp-Uno.Xaml-IsAotCompatible branch from 1826eb5 to 8861753 Compare December 31, 2025 21:03
@unodevops
Copy link
Contributor

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

1 similar comment
@unodevops
Copy link
Contributor

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

@jonpryor jonpryor force-pushed the dev/jonpryor/jonp-Uno.Xaml-IsAotCompatible branch 2 times, most recently from ecdeb3a to 24651c2 Compare January 2, 2026 18:26
@jonpryor jonpryor changed the title chore: Set $(IsAotCompatible)=true in Uno.Xaml chore: Address "downstream" trimmer warnings in Uno.Xaml.dll Jan 2, 2026
@jonpryor jonpryor marked this pull request as ready for review January 2, 2026 18:26
@jonpryor jonpryor requested a review from jeromelaban January 2, 2026 18:27
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22226/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-22226/docs/index.html

@unodevops
Copy link
Contributor

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

When *building* uno.chefs for NativeAOT with all warnings enabled:

	dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \
	  -bl Chefs/Chefs.csproj -p:UseSkiaRendering=true -p:SelfContained=true \
	  -p:PublishAot=true -p:IsAotCompatible=true -p:TrimmerSingleWarn=false -p:_ExtraTrimmerArgs=--verbose \
	  -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \
	  -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen

We observe the following warnings (among others):

	AOT analysis warning IL3050:
	  Uno.Xaml.Schema.XamlTypeName.XamlTypeName(XamlType): Using member 'System.Linq.Queryable.AsQueryable<XamlType>(IEnumerable`1<XamlType>)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
	  Enumerating in-memory collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime.
	  This may not work when AOT compiling.
	AOT analysis warning IL3050: Uno.Xaml.XamlSchemaContext.ResolveXamlTypeName(String,String,IList`1<XamlType>): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
	  The native code for this instantiation might not be available at runtime.

At a glance, `XamlTypeName` is an easy enough fix: don't use
`.AsQueryable()`.  @jonpryor doesn't see any need for it here.

`XamlSchemaContext.ResolveXamlTypeName()` looks similarly easy:
just add `[UnconditionalSuppressMessage]`, as is already done
elsewhere within `Uno.Xaml.dll`.

Additional thinking occurs: shouldn't this assembly be marked
as `$(IsAotCompatible)`=true?  Try that, and:

	/usr/local/share/dotnet/sdk/10.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(120,5): warning NETSDK1210:
	  IsAotCompatible and EnableAotAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:
	  <IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>

At which point everything becomes much more complicated:
`Uno.Xaml.csproj` targets `netstandard2.0`. When we multitarget *both*
netstandard2.0 and net10.0, everything breaks.
Because The World Has Moved On:

	src/SourceGenerators/System.Xaml/System.Xaml/XamlException.cs(78,24): error CS0672: Member 'XamlException.GetObjectData(SerializationInfo, StreamingContext)' overrides obsolete member 'Exception.GetObjectData(SerializationInfo, StreamingContext)'. …
	src/SourceGenerators/System.Xaml/System.Xaml/XamlException.cs(66,4): error SYSLIB0051: 'Exception.Exception(SerializationInfo, StreamingContext)' is obsolete: 'This API supports obsolete formatter-based serialization. It should not be called or extended by application code.'
	src/SourceGenerators/System.Xaml/System.Xaml/ParsedMarkupExtensionInfo.cs(153,31): error CA1865: Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char
	…

Explore this a bit, but ultimately come to the conclusion that it
isn't worthwhile:

 1. `Uno.Xaml.dll` needs to maintain netstandard2.0 compatibility,
    as it's refernced by source generators.

 2. Multitargeting .NET 10 just adds "noise".

 3. Attempting to fix warnings introduced by `$(IsAotCompatible)`=true
    is a fools errand: *everything* eventually hits various forms
    of Reflection such as `Type.MakeGenericType()` and/or
    `TypeDescriptor.GetConverter()`, meaning *everything* needs to be
    marked with `[RequiresDynamicCode]` and
    `[RequiresUnreferencedCode]`.  *Other than* introducing lots of
    warnings in referencing code, how does this *benefit* us?

    (It doesn't.)
@jonpryor jonpryor force-pushed the dev/jonpryor/jonp-Uno.Xaml-IsAotCompatible branch from 24651c2 to f5f2ba7 Compare January 8, 2026 14:16
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22226/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-22226/docs/index.html

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

Labels

area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants