From 42efef8cfd9acb6505d48322f6053190bc96ff8e Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Tue, 14 Apr 2026 14:22:39 +0200 Subject: [PATCH 1/2] Fix HybridWebView NativeAOT warning path Keep the HybridWebView handler registration on its own guarded local path so NativeAOT/full-trim analysis does not pick up the dynamic-code handler from the default controls registration list.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/Core/Hosting/AppHostBuilderExtensions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs b/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs index cb496527128f..82efff5eedfb 100644 --- a/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs +++ b/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs @@ -122,7 +122,17 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo handlersCollection.AddHandler(); if (RuntimeFeature.IsHybridWebViewSupported) { - // NOTE: not registered under NativeAOT or TrimMode=Full scenarios + // Keep the RequiresDynamicCode path isolated under the HybridWebView feature switch + // so NativeAOT/full-trim apps don't pick up HybridWebView warnings just by + // evaluating the default handler registration list. + AddHybridWebViewHandler(handlersCollection); + } +#if !NETSTANDARD + [RequiresDynamicCode(HybridWebViewHandler.DynamicFeatures)] +#endif + [RequiresUnreferencedCode(HybridWebViewHandler.DynamicFeatures)] + static void AddHybridWebViewHandler(IMauiHandlersCollection handlersCollection) + { handlersCollection.AddHandler(); } From 85b80da251d879e41ecabbe38756c990c0a9026d Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Tue, 14 Apr 2026 15:26:32 +0200 Subject: [PATCH 2/2] Address Copilot review on HybridWebView fix Use a local const string for the AOT/trimming annotation message instead of referencing HybridWebViewHandler.DynamicFeatures from Controls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs b/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs index 82efff5eedfb..a80b05204763 100644 --- a/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs +++ b/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs @@ -120,6 +120,7 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo handlersCollection.AddHandler(); handlersCollection.AddHandler(); handlersCollection.AddHandler(); + const string hybridWebViewDynamicFeatures = "HybridWebView uses dynamic System.Text.Json serialization features."; if (RuntimeFeature.IsHybridWebViewSupported) { // Keep the RequiresDynamicCode path isolated under the HybridWebView feature switch @@ -128,9 +129,9 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo AddHybridWebViewHandler(handlersCollection); } #if !NETSTANDARD - [RequiresDynamicCode(HybridWebViewHandler.DynamicFeatures)] + [RequiresDynamicCode(hybridWebViewDynamicFeatures)] #endif - [RequiresUnreferencedCode(HybridWebViewHandler.DynamicFeatures)] + [RequiresUnreferencedCode(hybridWebViewDynamicFeatures)] static void AddHybridWebViewHandler(IMauiHandlersCollection handlersCollection) { handlersCollection.AddHandler();