Skip to content

AOT integration tests fail: unexpected IL3050 warnings for HybridWebViewHandlerΒ #34867

Closed

Description

@PureWeen

Description

The PublishNativeAOTRootAllMauiAssemblies and PublishNativeAOT integration tests fail on Android (net11.0-android) because the expected warnings baseline doesn't include new IL3050 warnings from HybridWebViewHandler.

Error

Unexpected warning messages detected for the expected warnings file path 'ILC' and warning code 'IL3050'!
Unexpected warning messages are:
  Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.AddControlsHandlers(IMauiHandlersCollection):
    Using member 'Microsoft.Maui.Handlers.HybridWebViewHandler.HybridWebViewHandler()' which has
    'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
    HybridWebView uses dynamic System.Text.Json serialization features.

  Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.AddControlsHandlers(IMauiHandlersCollection):
    Using member 'Microsoft.Maui.Handlers.HybridWebViewHandler.HybridWebViewHandler(IPropertyMapper,CommandMapper)'
    which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
    HybridWebView uses dynamic System.Text.Json serialization features.

Affected Tests

  • AOTTemplateTest.PublishNativeAOTRootAllMauiAssemblies (android-x64, android-arm64)
  • AOTTemplateTest.PublishNativeAOT (android-x64, android-arm64)

Fails on both Windows and macOS AOT integration test jobs.

Repro

Observed on release/11.0.1xx-preview3 and net11.0 branches with Android SDK 36.99.0-preview.3.10.

Expected Fix

Update the expected warnings baseline in the AOT integration tests to include these IL3050 warnings for HybridWebViewHandler, or suppress the warning on the HybridWebViewHandler constructors.

Activity

  1. added this to the .NET 11.0-preview4 milestone on Apr 7, 2026
  2. PureWeen commented on Apr 9, 2026

    @PureWeen
    MemberAuthor

    Analysis

    The HybridWebViewHandler class is already annotated with [RequiresDynamicCode] and its registration in AddControlsHandlers is guarded by a [FeatureSwitchDefinition] feature switch:

    // src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs:123
    if (RuntimeFeature.IsHybridWebViewSupported)
    {
        // NOTE: not registered under NativeAOT or TrimMode=Full scenarios
        handlersCollection.AddHandler<HybridWebView, HybridWebViewHandler>();
    }

    The ILC linker will trim this code path when IsHybridWebViewSupported is false (which it is under NativeAOT/full trim). However, ILC still reports the IL3050 warning during analysis before applying the trim β€” so the warning is effectively a false positive for the trimmed output.

    Fix Options

    Option 1: Suppress at the call site (preferred)

    Add [UnconditionalSuppressMessage] to AddControlsHandlers since the feature switch already guards the call:

    [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode",
        Justification = "HybridWebViewHandler registration is guarded by RuntimeFeature.IsHybridWebViewSupported feature switch, which is disabled under NativeAOT/TrimMode=Full.")]

    This addresses the warning at its source rather than accepting it.

    Option 2: Update expected warnings baseline

    Add the two HybridWebViewHandler messages to ExpectedNativeAOTWarningsAndroid in BuildWarningsUtilities.cs. This just accepts the warning without fixing it.

    Recommendation

    Option 1 is the proper fix β€” the feature switch already ensures the code is trimmed, so suppressing the warning is correct and documenting why.

  3. simonrozsival commented on Apr 10, 2026

    @simonrozsival
    Member

    Suppressing the error is definitely not the right answer. Is it possible we enabled the RuntimeFeature.IsHybridWebViewSupported feature switch in a NativeAOT-enabled test? HWV won't work with Native AOT the way it is currently implemented (arbitrary JSON serialization/deserialization)

  4. PureWeen commented on Jun 10, 2026

    @PureWeen
    MemberAuthor

    Closed by #34958 (merged to net11.0). GitHub only auto-closes for PRs merged to the default branch; this issue was fixed by a PR merged to a non-default branch.

  5. added a commit that references this issue on Jun 22, 2026
    71b880a
  6. locked and limited conversation to collaborators on Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

s/triagedIssue has been reviewed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions