Fix AOT integration test failures: suppress IL3050/IL2026 for HybridWebViewHandler in AddControlsHandlers#34868
Conversation
…dControlsHandlers The Android NativeAOT ILC does not honor [FeatureGuard] for IL3050/IL2026 warning suppression (unlike the iOS/macCatalyst ILC). Since the code is already correctly guarded by RuntimeFeature.IsHybridWebViewSupported which has [FeatureGuard(RequiresUnreferencedCodeAttribute)] and [FeatureGuard(RequiresDynamicCodeAttribute)] annotations, and because MauiHybridWebViewSupported=false disables HybridWebView in NativeAOT/ TrimMode=Full scenarios, we explicitly suppress the warnings with pragma. Agent-Logs-Url: https://github.com/dotnet/maui/sessions/830e28e9-d06a-44ff-991f-6e98c69e14e5 Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
🤖 AI Summary
📊 Review Session —
|
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #34868 | Add #pragma warning disable IL2026, IL3050 around AddHandler<HybridWebView, HybridWebViewHandler>() |
⏳ PENDING (Gate skipped — no tests) | AppHostBuilderExtensions.cs |
Original PR; LGTM from code review |
🔬 Code Review — Deep Analysis
Code Review — PR #34868
Independent Assessment
What this changes: Adds #pragma warning disable IL2026, IL3050 / #pragma warning restore IL2026, IL3050 wrapping the single call to handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>(), and expands the existing comment to explain why the suppression is needed.
Inferred motivation: HybridWebViewHandler is annotated [RequiresUnreferencedCode] + [RequiresDynamicCode]. The call site is inside an if (RuntimeFeature.IsHybridWebViewSupported) guard, which carries [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))] and [FeatureGuard(typeof(RequiresDynamicCodeAttribute))] on .NET 9+. That guard is supposed to tell the ILC "this code is unreachable when trimming/AOT is active," suppressing the warnings. The iOS/macCatalyst ILC honors this; the Android NativeAOT ILC (SDK 36.99.0-preview.3.10) does not, so the warnings leak and break the AOT integration tests which treat them as errors.
Reconciliation with PR Narrative
Author claims: Android ILC doesn't honor [FeatureGuard] for warning suppression; the explicit pragma is the correct workaround, matching the ResourceDictionaryHelpers.cs precedent.
Agreement: Full agreement. Verified:
RuntimeFeature.IsHybridWebViewSupportedhas the[FeatureGuard]annotations guarded under#if NET9_0_OR_GREATER✅HybridWebViewHandlercarries both[RequiresUnreferencedCode]and[RequiresDynamicCode]✅ResourceDictionaryHelpers.csuses the identical#pragma warning disable IL2026, IL3050pattern for a feature-guarded call ✅- The second
IsHybridWebViewSupportedblock (line 257,HybridWebViewTaskManager) is correctly left without a pragma —HybridWebViewTaskManagerhas no trim/AOT annotations ✅ - The pragma scope is minimal: one line, tightly wrapped ✅
Findings
No errors, warnings, or suggestions. The change is correct, minimal, and follows established codebase conventions.
CI Status
| Job | Status |
|---|---|
maui-pr (Build macOS Debug) |
❌ fail (unrelated to PR) |
maui-pr (Build macOS Release) |
✅ pass |
| All other jobs | ✅ pass |
The macOS Debug failure is unrelated to this PR. A pragma-only diff cannot cause a platform build failure, and the Release macOS build passes.
Devil's Advocate
- "Could the pragma suppress a legitimate warning?" — No. The call is correctly inside the feature guard. The
[FeatureGuard]mechanism exists precisely to communicate that the code is dead when trimming is active. - "Should this be
[UnconditionalSuppressMessage]instead?" — No.[UnconditionalSuppressMessage]is a method-level attribute and would suppress too broadly.#pragmascoped to a single line is correct, matchingResourceDictionaryHelpers.cs. - "Is the comment accurate?" — Yes. It correctly describes both what's guarded and why Android ILC behaves differently.
Verdict: LGTM
Confidence: high
Summary: The change is a narrow, well-justified pragma suppression for an Android NativeAOT ILC deficiency. It follows the established codebase pattern, is correctly scoped, and the expanded comment accurately explains the situation. The single failing CI job (macOS Debug) is not caused by this PR. Ready for human approval.
🔧 Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix (claude-opus-4.6) | Extract to AddHybridWebViewHandler() private method with [UnconditionalSuppressMessage("AOT","IL3050")] + [UnconditionalSuppressMessage("Trimming","IL2026")] |
1 file | No Android NativeAOT environment; code compiled clean (net10.0) | |
| 2 | try-fix (claude-sonnet-4.6) | #if ANDROID-scoped #pragma warning disable IL2026, IL3050 / restore |
1 file | More verbose (6 lines vs 2), inconsistent with codebase — all other IL2026/IL3050 suppressions are unconditional | |
| 3 | try-fix (gpt-5.3-codex) | Update BuildWarningsUtilities.cs to treat Android IL2026/IL3050 for HybridWebView as optional known warnings (remove from assertion) |
2 files | Semantically wrong: marks warnings as "known" rather than fixing source; complex infra change | |
| 4 | try-fix (gpt-5.4) | Use non-generic AddHandler(typeof(HybridWebView), typeof(HybridWebViewHandler)) to avoid generic instantiation |
1 file | May not work — HybridWebViewHandler warnings stem from type annotation, not generic instantiation | |
| PR | PR #34868 | #pragma warning disable IL2026, IL3050 / #pragma warning restore wrapping single AddHandler<HybridWebView, HybridWebViewHandler>() |
⏳ PENDING (Gate skipped) | 1 file | LGTM from code review; minimal, consistent with codebase pattern |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| claude-opus-4.6 | 2 | YES | ILLink.Substitutions.xml to define IsHybridWebViewSupported as ILC feature switch — already implemented via RuntimeHostConfigurationOption Trim="true" in Microsoft.Maui.Controls.targets:338-341; doesn't address Android ILC warning emission behavior |
| (all models) | 2 | NO NEW IDEAS | After reviewing the ILLink.Substitutions approach is already covered |
Exhausted: Yes — all 4 models produced Blocked results due to missing Android NativeAOT environment; no approach demonstrated empirical superiority over the PR's fix
Selected Fix: PR's fix — #pragma warning disable IL2026, IL3050 directly at call site. Minimal (2 lines), follows established codebase pattern (ResourceDictionaryHelpers.cs:95), platform-neutral, correct.
📋 Report — Final Recommendation
✅ Final Recommendation: APPROVE
Phase Status
| Phase | Status | Notes |
|---|---|---|
| Pre-Flight | ✅ COMPLETE | No linked issue; 1 file changed (AppHostBuilderExtensions.cs), 0 tests |
| Code Review | LGTM (high) | 0 errors, 0 warnings, 0 suggestions |
| Gate | No tests detected in PR — consider suggesting author add AOT integration test | |
| Try-Fix | ✅ COMPLETE | 4 attempts, 0 empirically passing (all Blocked — no Android NativeAOT environment) |
| Report | ✅ COMPLETE |
Code Review Impact on Try-Fix
Code review returned LGTM (high confidence) with no errors or warnings. This meant try-fix models had no specific code defects to address; they explored alternative suppression approaches (UnconditionalSuppressMessage, #if ANDROID pragma, test baseline update, non-generic API) as diversity exercises. The reviewer found one minor comment inaccuracy (typeof() missing from attribute references in comment) which was applied as the pr-plus-reviewer candidate. No try-fix approach produced a clearly superior fix — all were blocked by missing Android NativeAOT toolchain and evaluated as more complex or less idiomatic than the PR's solution.
Summary
PR #34868 is a narrow, focused fix for an Android NativeAOT ILC deficiency. The Android ILC (SDK 36.99.0-preview.3.10) does not honor [FeatureGuard] annotations for warning suppression when analyzing HybridWebViewHandler, unlike the iOS/macCatalyst ILC. The PR's fix — adding #pragma warning disable IL2026, IL3050 / restore around the single affected line — is correct, minimal, and consistent with the established codebase pattern (ResourceDictionaryHelpers.cs:95, AppleIntelligenceChatClient.cs:340). The pr-plus-reviewer candidate adds minor comment polish (correct typeof() syntax, #if NET9_0_OR_GREATER note, TODO for future removal) but both are equivalent in correctness.
Root Cause
The Android NativeAOT ILC analyzes HybridWebViewHandler (which carries [RequiresDynamicCode] + [RequiresUnreferencedCode]) and emits IL3050/IL2026 warnings despite the call site being inside if (RuntimeFeature.IsHybridWebViewSupported). The IsHybridWebViewSupported property correctly carries [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))] and [FeatureGuard(typeof(RequiresDynamicCodeAttribute))] (under #if NET9_0_OR_GREATER), which the iOS/macCatalyst ILC respects but the Android ILC does not. This is an upstream Android ILC bug; the pragma workaround is appropriate until it is resolved.
Fix Quality
The PR's fix is correct and appropriate:
- Minimal scope: 2-line pragma wraps exactly one call
- Well-justified: Comment explains the cross-platform ILC behavioral difference
- Consistent with codebase: Matches
ResourceDictionaryHelpers.cs,AppleIntelligenceChatClient.cspatterns - Not over-suppressing: Second
IsHybridWebViewSupportedcheck (line 257,HybridWebViewTaskManager) correctly left without pragma — that class has no AOT annotations - Selected Fix: PR — PR's fix is the best candidate
Winner: pr-plus-reviewer — The PR's fix is correct as-is; the pr-plus-reviewer candidate adds helpful comment precision (typeof(), #if NET9_0_OR_GREATER notation, TODO) with no behavioral change. Either candidate is approvable.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>(); | ||
| #pragma warning restore IL2026, IL3050 | ||
| } | ||
|
|
There was a problem hiding this comment.
[minor] Logic and Correctness / Comment Accuracy — The comment says [FeatureGuard(RequiresUnreferencedCodeAttribute)] but the actual C# attribute syntax (in RuntimeFeature.cs:87-88) requires typeof(): [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))]. The omission of typeof() is misleading for developers trying to cross-reference the attribute. The comment also does not note that these [FeatureGuard] annotations exist only under #if NET9_0_OR_GREATER, which is relevant context for why the pragma is needed.
Suggested replacement comment:
// has [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))] and
// [FeatureGuard(typeof(RequiresDynamicCodeAttribute))] annotations (under #if NET9_0_OR_GREATER)
// that should suppress these warnings. The Android NativeAOT ILC does not honor
// [FeatureGuard] for warning suppression (unlike the iOS/macCatalyst ILC), so we suppress
// explicitly. TODO: Remove this pragma once the Android ILC honors [FeatureGuard].There was a problem hiding this comment.
Pull request overview
Suppresses Android NativeAOT ILC IL3050/IL2026 warnings emitted for HybridWebViewHandler registration in AddControlsHandlers, aligning behavior with other toolchains that already honor the existing feature guard.
Changes:
- Adds an explicit
#pragma warning disable/restore IL2026, IL3050aroundAddHandler<HybridWebView, HybridWebViewHandler>()under theRuntimeFeature.IsHybridWebViewSupportedguard. - Expands the inline comment to document why the suppression is necessary (Android NativeAOT ILC not honoring
[FeatureGuard]).
| // IL2026/IL3050 are suppressed because the RuntimeFeature.IsHybridWebViewSupported guard | ||
| // has [FeatureGuard(RequiresUnreferencedCodeAttribute)] and [FeatureGuard(RequiresDynamicCodeAttribute)] | ||
| // annotations that should suppress these warnings. The Android NativeAOT ILC does not honor | ||
| // [FeatureGuard] for warning suppression (unlike the iOS/macCatalyst ILC), so we suppress explicitly. |
…ebViewHandler in AddControlsHandlers (#34868) `AOTTemplateTest.PublishNativeAOT` and `PublishNativeAOTRootAllMauiAssemblies` fail on Android NativeAOT because the Android ILC (SDK 36.99.0-preview.3.10) emits unexpected `IL3050` warnings for `HybridWebViewHandler` constructors—despite the call site already being correctly guarded by a `[FeatureGuard]`-annotated feature switch. ## Why the warnings appear `HybridWebViewHandler` carries `[RequiresDynamicCode]`/`[RequiresUnreferencedCode]` because it uses dynamic `System.Text.Json` serialization. The registration in `AddControlsHandlers` is inside a proper feature guard: ```csharp // RuntimeFeature.IsHybridWebViewSupported has: // [FeatureGuard(typeof(RequiresDynamicCodeAttribute))] // [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))] // MauiHybridWebViewSupported=false is set by MSBuild targets when PublishAot=true if (RuntimeFeature.IsHybridWebViewSupported) { handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>(); } ``` The iOS/macCatalyst NativeAOT ILC correctly honors `[FeatureGuard]` and suppresses the warnings. The Android NativeAOT ILC does not, so `IL3050`/`IL2026` leak through and break the test's strict warning-baseline check. ## Fix Explicitly suppress with `#pragma` at the affected call site—the same pattern used elsewhere in the codebase (`ResourceDictionaryHelpers.cs`, etc.) for ILC warnings on code that is provably safe via a feature guard: ```csharp if (RuntimeFeature.IsHybridWebViewSupported) { // NOTE: not registered under NativeAOT or TrimMode=Full scenarios. // IL2026/IL3050 suppressed because IsHybridWebViewSupported has [FeatureGuard] annotations // for both RequiresUnreferencedCode and RequiresDynamicCode. The Android NativeAOT ILC does // not honor [FeatureGuard] for warning suppression (unlike iOS/macCatalyst), so suppress explicitly. #pragma warning disable IL2026, IL3050 handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>(); #pragma warning restore IL2026, IL3050 } ``` No baseline changes needed—the pragma suppression is respected by the ILC so the warnings are no longer emitted. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
…ebViewHandler in AddControlsHandlers (#34868) `AOTTemplateTest.PublishNativeAOT` and `PublishNativeAOTRootAllMauiAssemblies` fail on Android NativeAOT because the Android ILC (SDK 36.99.0-preview.3.10) emits unexpected `IL3050` warnings for `HybridWebViewHandler` constructors—despite the call site already being correctly guarded by a `[FeatureGuard]`-annotated feature switch. ## Why the warnings appear `HybridWebViewHandler` carries `[RequiresDynamicCode]`/`[RequiresUnreferencedCode]` because it uses dynamic `System.Text.Json` serialization. The registration in `AddControlsHandlers` is inside a proper feature guard: ```csharp // RuntimeFeature.IsHybridWebViewSupported has: // [FeatureGuard(typeof(RequiresDynamicCodeAttribute))] // [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))] // MauiHybridWebViewSupported=false is set by MSBuild targets when PublishAot=true if (RuntimeFeature.IsHybridWebViewSupported) { handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>(); } ``` The iOS/macCatalyst NativeAOT ILC correctly honors `[FeatureGuard]` and suppresses the warnings. The Android NativeAOT ILC does not, so `IL3050`/`IL2026` leak through and break the test's strict warning-baseline check. ## Fix Explicitly suppress with `#pragma` at the affected call site—the same pattern used elsewhere in the codebase (`ResourceDictionaryHelpers.cs`, etc.) for ILC warnings on code that is provably safe via a feature guard: ```csharp if (RuntimeFeature.IsHybridWebViewSupported) { // NOTE: not registered under NativeAOT or TrimMode=Full scenarios. // IL2026/IL3050 suppressed because IsHybridWebViewSupported has [FeatureGuard] annotations // for both RequiresUnreferencedCode and RequiresDynamicCode. The Android NativeAOT ILC does // not honor [FeatureGuard] for warning suppression (unlike iOS/macCatalyst), so suppress explicitly. #pragma warning disable IL2026, IL3050 handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>(); #pragma warning restore IL2026, IL3050 } ``` No baseline changes needed—the pragma suppression is respected by the ILC so the warnings are no longer emitted. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
AOTTemplateTest.PublishNativeAOTandPublishNativeAOTRootAllMauiAssembliesfail on Android NativeAOT because the Android ILC (SDK 36.99.0-preview.3.10) emits unexpectedIL3050warnings forHybridWebViewHandlerconstructors—despite the call site already being correctly guarded by a[FeatureGuard]-annotated feature switch.Why the warnings appear
HybridWebViewHandlercarries[RequiresDynamicCode]/[RequiresUnreferencedCode]because it uses dynamicSystem.Text.Jsonserialization. The registration inAddControlsHandlersis inside a proper feature guard:The iOS/macCatalyst NativeAOT ILC correctly honors
[FeatureGuard]and suppresses the warnings. The Android NativeAOT ILC does not, soIL3050/IL2026leak through and break the test's strict warning-baseline check.Fix
Explicitly suppress with
#pragmaat the affected call site—the same pattern used elsewhere in the codebase (ResourceDictionaryHelpers.cs, etc.) for ILC warnings on code that is provably safe via a feature guard:No baseline changes needed—the pragma suppression is respected by the ILC so the warnings are no longer emitted.