chore: Fix trimmer warnings - #2954
Merged
Merged
Conversation
jonpryor
force-pushed
the
dev/jonpryor/jonp-fix-trimmer-warnings
branch
2 times, most recently
from
November 26, 2025 18:50
ef159b3 to
e4157bf
Compare
jonpryor
marked this pull request as ready for review
November 26, 2025 18:51
dr1rrb
reviewed
Dec 1, 2025
Context: dotnet/runtime#121629 Context: dea3b57 / 56a003b [may not exist] Context: c3c4c78 Enable `$(IsAotCompatible)`=true for the following projects: * `src/Uno.Extensions.Core/Uno.Extensions.Core.csproj` * `src/Uno.Extensions.Navigation/Uno.Extensions.Navigation.csproj` * `src/Uno.Extensions.Reactive/Uno.Extensions.Reactive.csproj` Fix the following warnings-as-errors: src/Uno.Extensions.Core/DependencyInjection/ServiceCollectionExtensions.cs(24,3): error IL2091: 'TService' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAddTransient<TService>(IServiceCollection)'. The generic parameter 'TImplementation' of 'Uno.Extensions.ServiceCollectionExtensions.AddNamedSingleton<TService, TImplementation>(IServiceCollection, String)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src/Uno.Extensions.Navigation/MappedViewMap.cs(14,6): error IL2067: 'ViewModel' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Uno.Extensions.Navigation.ViewMap.ViewMap(Type, Func<Type>, Type, DataMap, Type, Object)'. The parameter 'ViewModel' of method 'Uno.Extensions.Navigation.MappedViewMap.MappedViewMap(Type, Func<Type>, Type, DataMap, Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src/Uno.Extensions.Navigation/ViewMap.cs(66,5): error IL2087: 'ViewModel' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Uno.Extensions.Navigation.ViewMap<TView>.ViewMap(Type, DataMap, Type, Object)'. The generic parameter 'TViewModel' of 'Uno.Extensions.Navigation.ViewMap<TView, TViewModel>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src/Uno.Extensions.Navigation/ViewMap.cs(86,15): error IL2091: 'TViewModel' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in 'Uno.Extensions.Navigation.ViewMap<TView, TViewModel>'. The generic parameter 'TViewModel' of 'Uno.Extensions.Navigation.ResultDataViewMap<TView, TViewModel, TResultData>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(102,15): error IL2067: 'updatedModelType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Uno.Extensions.Reactive.Bindings.BindableViewModelBase.__Reactive_CreateModelInstance(Type)'. The parameter 'updatedModelType' of method 'Uno.Extensions.Reactive.Bindings.BindableViewModelBase.HotPatch(Type, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src/Uno.Extensions.Reactive/Collections/Facades/Map/LockedMemoizedConverter.cs(20,75): error IL2091: 'TValue' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'System.Runtime.CompilerServices.ConditionalWeakTable<TKey, TValue>'. The generic parameter 'TFrom' of 'Uno.Extensions.Conversion.LockedMemoizedConverter<TFrom, TTo>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. … src/Uno.Extensions.Reactive/Collections/Facades/Map/OneWayMemoizedConverter.cs(19,75): error IL2091: 'TValue' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'System.Runtime.CompilerServices.ConditionalWeakTable<TKey, TValue>'. The generic parameter 'TFrom' of 'Uno.Extensions.Conversion.OneWayMemoizedConverter<TFrom, TTo>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. … src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(405,41): error IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Uno.Extensions.Reactive.Bindings.BindableViewModelBase.IsFeed(Type, out Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. Add the missing `[DynamicallyAccessedMembers]`. Address the following warnings-as-errors: src/Uno.Extensions.Navigation/ViewMap.cs(44,5): error IL2067: 'ViewModel' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Uno.Extensions.Navigation.ViewMap.ViewMap(Type, Func<Type>, Type, DataMap, Type, Object)'. The parameter 'Data' of method 'Uno.Extensions.Navigation.ViewMap<TView>.ViewMap(Type, DataMap, Type, Object)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. This is dotnet/runtime#121629. Work around it by providing the `ViewSelector: null` parameter. Address the following warning-as-errors: src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(353,31): error IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(357,31): error IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(349,31): error IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. Add `[RequiresDynamicCode]` to "forward" the IL3050 to callers. Suppress the following warning-as-error: src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(394,30): error IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'Uno.Extensions.Reactive.Bindings.BindableViewModelBase.IsFeed(Type, out Type)'. The return value of method 'System.Reflection.PropertyInfo.PropertyType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. This IL2072 is "forwarded" from an above change to `IsFeed()`, and I don't know how to properly forward or address at this callsite. Suppress the following warning-as-error: src/Uno.Extensions.Reactive/Core/HotReload/HotReloadService.cs(11,12): error IL2026: Using member 'Uno.Extensions.Reactive.Core.HotReload.HotReloadService.UpdateApplication(Type[])' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. `MetadataUpdateOriginalTypeAttribute` may be a per-assembly type, so it cannot be statically known. This is on an `[assembly:]`-level attribute. I can think of only using `#pragma warning disable` to remove the error. Suppress the following warning-as-error: src/Uno.Extensions.Navigation/RouteInfo.cs(27,29): error IL2073: 'Uno.Extensions.Navigation.RouteInfo.RenderView.get' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' requirements. The return value of method 'System.Func<TResult>.Invoke()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. Remember 56a003b (which has the comment, merged into dea3b57)? > Add `[DynamicallyAccessedMembers]` to `RouteInfo.RenderView`. This > is a bit of a lie, as `RenderView` invokes `View`…: > … > and there is no way to update the `View` parameter to assert that the > returned `Type` fulfills the requirements. Oddly, this doesn't require > suppressing anything… *Now* it needs suppressing. We can't change the parameter type without incurring an ABI break. TODO: use constructor overloading? Look into `System.Runtime.CompilerServices.OverloadResolutionPriority`. For the following warning-as-errors: src/Uno.Extensions.Navigation/NavigationRequestExtensions.cs(115,30): error IL2060: Call to 'System.Reflection.MethodInfo.MakeGenericMethod(params Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. src/Uno.Extensions.Navigation/NavigationRequestExtensions.cs(115,30): error IL3050: Using member 'System.Reflection.MethodInfo.MakeGenericMethod(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. This was apparently added in c3c4c78. For now, "suppress and wrap" the warning: the warning is suppressed, and we "wrap" in `[RequiresDynamicCode]`. Address the following warning-as-error: src/Uno.Extensions.Http/ServiceCollectionExtensions.cs(117,15): error IL3050: Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.Get<T>(IConfiguration)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Binding strongly typed objects to configuration values requires generating dynamic code at runtime, for example instantiating generic types. TODO: understand why generics were added to this codepath, and possibly *remove* them? At a glance, the generics don't appear to be publicly visible… For now, Add `[RequiresUnreferencedCode]` to `AddClientWithEndpoint()`. Address the following warnings-as-errors: src/Uno.Extensions.Reactive/Core/HotReload/HotReloadService.cs(69,8): error IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. The reflection use is required, and this is part of the HotReload codepath, so annotate with `[RequiresUnreferencedCode]`. Address the following warnings-as-errors: src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(86,85): error IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize(Object, Type, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(104,89): error IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize(String, Type, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. src/Uno.Extensions.Reactive/Presentation/Bindings/BindableViewModelBase.HotReload.cs(403,41): error IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter 'type' of method 'Uno.Extensions.Reactive.Bindings.BindableViewModelBase.IsFeed(Type, out Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. Add `[RequiresDynamicCodeAttribute]` or `[RequiresUnreferencedCode]`, depending on the warning message.
jonpryor
force-pushed
the
dev/jonpryor/jonp-fix-trimmer-warnings
branch
from
December 1, 2025 21:10
e4157bf to
f4198de
Compare
dr1rrb
approved these changes
Dec 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: dotnet/runtime#121629
Context: dea3b57 / 56a003b [may not exist]
Context: c3c4c78
Enable
$(IsAotCompatible)=true for the following projects:src/Uno.Extensions.Core/Uno.Extensions.Core.csprojsrc/Uno.Extensions.Navigation/Uno.Extensions.Navigation.csprojsrc/Uno.Extensions.Reactive/Uno.Extensions.Reactive.csprojFix the following warnings-as-errors:
Add the missing
[DynamicallyAccessedMembers].Address the following warnings-as-errors:
This is dotnet/runtime#121629. Work around it by providing the
ViewSelector: nullparameter.Address the following warning-as-errors:
Add
[RequiresDynamicCode]to "forward" the IL3050 to callers.Suppress the following warning-as-error:
This IL2072 is "forwarded" from an above change to
IsFeed(), and Idon't know how to properly forward or address at this callsite.
Suppress the following warning-as-error:
This is on an
[assembly:]-level attribute. I can think of onlyusing
#pragma warning disableto remove the error.Suppress the following warning-as-error:
Remember 56a003b (which has the comment, merged into dea3b57)?
Now it needs suppressing. We can't change the parameter type without
incurring an ABI break.
TODO: use constructor overloading?
Look into
System.Runtime.CompilerServices.OverloadResolutionPriority.For the following warning-as-errors:
This was apparently added in c3c4c78.
For now, "suppress and wrap" the warning: the warning is suppressed,
and we "wrap" in
[RequiresDynamicCode].Address the following warning-as-error:
TODO: understand why generics were added to this codepath, and
possibly remove them? At a glance, the generics don't appear to be
publicly visible…
For now, Add
[RequiresUnreferencedCode]toAddClientWithEndpoint().Address the following warnings-as-errors:
The reflection use is required, and this is part of the
HotReload codepath, so annotate with
[RequiresUnreferencedCode].Address the following warnings-as-errors:
Add
[RequiresDynamicCodeAttribute]or[RequiresUnreferencedCode],depending on the warning message.