Repository navigation
NativeAOT/trimming warnings with AsyncNavigation.Avalonia 2.0.2 and Avalonia 12.1.3 #60
Description
The README advertises full Avalonia NativeAOT/trimming support without extra configuration. Publishing a minimal application using AsyncNavigation.Avalonia 2.0.2 with Avalonia 12.1.3 produces IL2026, IL3050, and IL2091 warnings from the navigation packages.
There is no application XAML, reflection binding, warning suppression, or trimmer root descriptor in this reproduction.
Environment
- Windows x64
- .NET SDK:
11.0.100-rc.1.26425.128 - Target framework:
net10.0(the same warnings also appeared in anet11.0-windowsapplication) AsyncNavigation.Avalonia:2.0.2Avalonia:12.1.3Microsoft.Extensions.DependencyInjection:10.0.11
Minimal reproduction
Repro.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PublishAot>true</PublishAot>
<IsAotCompatible>true</IsAotCompatible>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncNavigation.Avalonia" Version="2.0.2" />
<PackageReference Include="Avalonia" Version="12.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
</ItemGroup>
</Project>Program.cs:
using AsyncNavigation;
using AsyncNavigation.Abstractions;
using Avalonia.Controls;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddNavigationSupport().RegisterNavigation<SampleView, SampleViewModel>("sample");
using var provider = services.BuildServiceProvider();
Console.WriteLine(provider.GetRequiredService<IRegionManager>().GetType().Name);
public sealed class SampleView : UserControl, IView;
public sealed class SampleViewModel : NavigationAwareBase;Publish:
dotnet publish Repro.csproj -c Release -r win-x64The publication succeeds. The resulting native executable also exits successfully and prints RegionManager. This reproduction checks registration/resolution only; it does not establish that every navigation or dialog feature fails at runtime.
Observed diagnostics
| Location | Warnings | Reported operation |
|---|---|---|
ContentRegion.InitializeOnRegionCreated |
IL2026, IL3050 |
Avalonia.Data.Binding.Binding(string) |
ItemsRegionBase.InitializeOnRegionCreated, TabRegion.InitializeOnRegionCreated, TabbedPageRegion.InitializeOnRegionCreated |
IL2026, IL3050 |
Avalonia.Data.Binding.Binding(string) |
IconResolver.ResolveResourceKey, IconResolver.ResolvePathData |
IL2026, IL3050 |
Avalonia.Data.Binding.Binding(string) |
DefaultDialogContainer.!XamlIlPopulate |
IL2026, IL3050 |
ReflectionBindingExtension(string) |
RegisterViewModelAndView<TView, TViewModel, TAware> |
IL2091 for both TView and TViewModel |
Generic arguments do not satisfy the PublicConstructors requirement of AddTransient<TService> |
AddNavigationSupport and the registration call in Program.cs |
IL3050 |
System.Enum.GetValues(Type) |
Representative messages, with local paths omitted:
IL2026: AsyncNavigation.Avalonia.ContentRegion.InitializeOnRegionCreated(ContentControl):
Using member 'Avalonia.Data.Binding.Binding(String)' which has
'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code.
IL3050: AsyncNavigation.Avalonia.ContentRegion.InitializeOnRegionCreated(ContentControl):
Using member 'Avalonia.Data.Binding.Binding(String)' which has
'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
IL2091: RegisterViewModelAndView<TView,TViewModel,TAware>:
The generic parameter 'TView' does not have matching annotations for
'DynamicallyAccessedMemberTypes.PublicConstructors' required by AddTransient<TService>.
The same warning is reported for 'TViewModel'.
IL3050: AddNavigationSupport(IServiceCollection,NavigationOptions):
Using member 'System.Enum.GetValues(Type)' which has 'RequiresDynamicCodeAttribute'.
Expected behavior / possible fixes
NativeAOT publication should not require applications to suppress these warnings to use the advertised supported configuration.
Could the internal code bindings and dialog XAML use compiled/typed bindings, and could the required constructor-preservation annotations be propagated through the private RegisterViewModelAndView helper? The Enum.GetValues(Type) diagnostic also needs investigation; I have not identified its exact underlying source call.
Enabling the trimming/AOT analyzers for the packages and adding a small NativeAOT publication test would help catch regressions. If this Avalonia version is outside the supported compatibility range, please document that range instead.
Activity
RoccoZero commentedon Oct 8, 2026
Here is a tested patch for the region bindings and default dialog title from this report. It targets the 2.0.2 source revision
99f457b685f4315db586ce8d0d9f83cf176d9723.The seven code bindings use
CompiledBinding.Createwith typedRegionContextexpressions. Their existing sources and binding modes are preserved, including TwoWay selection. The dialog XAML usesIDialogAwareas its data type and a compiled Title binding.Patch
Validation
IL2026,IL3050, andIL2091are treated as errors.net11.0,win-x64, SDK11.0.100-rc.1.26425.128) without trimming/AOT diagnostics, and the native executable passed the same 14 checks.git apply --checkagainst the 2.0.2 source.This verifies the binding primitives and compiled dialog XAML; it is not a full end-to-end test of every navigation or dialog lifecycle.
This is a partial fix for #60: the two ancestor Foreground bindings in
IconResolver, the private DI helper's constructor-preservation annotations, and theEnum.GetValues(Type)diagnostic still need separate fixes. No warning suppression or application trimmer roots are added by this patch.I also submitted the separate shutdown/disposal candidate patch in #61.