Android framework version
net11.0-android (Preview)
Affected platform version
Microsoft.NET.Sdk.Android 36.99.0-ci.main.254, Microsoft.NET.Sdk.Maui 11.0.0-preview.4.26266.2, .NET runtime 11.0.0-preview.5.26269.119
Description
A MAUI 11 Android app generated from the --sample-content template crashes during the first activity launch as soon as the initial page is realized. The failure reproduces across all three Android runtime flavors and only differs in the surface exception:
- CoreCLR Default —
System.TypeLoadException: the generic [ElementHandler<CheckBoxHandler>] attribute on Microsoft.Maui.Controls.CheckBox fails its constraint check at the point handler resolution materializes the attribute.
- Mono Default —
Microsoft.Maui.Platform.HandlerNotFoundException: handler resolution returns no attribute, so MauiHandlersFactory cannot find a handler for CheckBox.
- NativeAOT CoreCLR — Same
HandlerNotFoundException as Mono.
All three crash on the main thread while binding a CollectionView item template that contains a CheckBox, so the activity is force-finished and never reports Displayed/COLD to ActivityManager.
Debug-configuration builds appear unaffected — this is observed only on Release (and on NativeAOT, which is implicitly Release-like).
A trivial MAUI Android app (dotnet new maui without --sample-content, no CheckBox in the visual tree) launches and renders normally on the same workload and runtime, so the failure is specific to types that rely on the [ElementHandler<T>] attribute discovery path for CheckBox.
Steps to Reproduce
- Install the preview workload:
dotnet workload install maui --from-rollback-file rollback.json
where rollback.json pins:
microsoft.net.sdk.android = 36.99.0-ci.main.254 / 11.0.100-preview.5
microsoft.net.sdk.maui = 11.0.0-preview.4.26266.2 / 11.0.100-preview.5
- Create the sample-content MAUI template:
dotnet new maui --name MauiSampleContentAndroid --sample-content
- Build and publish an Android APK with CoreCLR (Mono and NativeAOT reproduce too):
dotnet publish -c Release -f net11.0-android -r android-arm64 --self-contained /p:UseMonoRuntime=false
- Install on a physical Android device and launch via
am:
adb install -r -t bin/Release/net11.0-android/android-arm64/publish/com.companyname.mauisamplecontentandroid-Signed.apk
adb shell am start-activity -W -n com.companyname.mauisamplecontentandroid/crc64240ecb5b7da1ec7e.MainActivity
Expected: app reaches first frame, ActivityManager logs Displayed com.companyname.mauisamplecontentandroid/...MainActivity.
Actual: am start-activity -W returns LaunchState: UNKNOWN (0); logcat shows FATAL EXCEPTION: main and ActivityManager: Showing crash dialog for package com.companyname.mauisamplecontentandroid; no Displayed line is emitted.
Did you find any workaround?
None yet. Adding the missing handler registration manually (e.g. handlers.AddHandler<CheckBox, CheckBoxHandler>() in MauiProgram.CreateMauiApp) avoids the HandlerNotFoundException on Mono/NativeAOT, but the System.TypeLoadException on CoreCLR still triggers when the attribute is enumerated.
Relevant log output
CoreCLR Default (Pixel 8)
05-25 03:24:49.504 ActivityTaskManager: START u0 {flg=0x10000000 cmp=com.companyname.mauisamplecontentandroid/crc64240ecb5b7da1ec7e.MainActivity} with LAUNCH_SINGLE_TOP from uid 2000 (BAL_ALLOW_PERMISSION) result code=0
05-25 03:24:49.518 ActivityManager: Start proc 9591:com.companyname.mauisamplecontentandroid/u0a6050 for next-top-activity {com.companyname.mauisamplecontentandroid/crc64240ecb5b7da1ec7e.MainActivity}
05-25 03:24:50.233 AndroidRuntime: Shutting down VM
05-25 03:24:50.233 AndroidRuntime: FATAL EXCEPTION: main
05-25 03:24:50.233 AndroidRuntime: Process: com.companyname.mauisamplecontentandroid, PID: 9591
05-25 03:24:50.233 AndroidRuntime: android.runtime.JavaProxyThrowable: [System.TypeLoadException]: GenericArguments[0], 'Microsoft.Maui.Handlers.CheckBoxHandler', on 'Microsoft.Maui.Handlers.ElementHandlerAttribute`1[THandler]' violates the constraint of type parameter 'THandler'.
05-25 03:24:50.233 AndroidRuntime: at System.ModuleHandle.ResolveType + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.ModuleHandle.ResolveTypeHandle + 0xa5(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Reflection.RuntimeModule.ResolveType + 0x8a(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Reflection.CustomAttribute.FilterCustomAttributeRecord + 0x8(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Reflection.CustomAttribute.AddCustomAttributes + 0x43(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Reflection.CustomAttribute.GetCustomAttributes + 0xc3(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Attribute.GetCustomAttributes + 0x75(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Attribute.GetCustomAttribute + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Reflection.CustomAttributeExtensions.GetCustomAttribute + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler + 0x1d(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToPlatform + 0x14(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView + 0x76(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler + 0x7e(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler + 0xae(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToPlatform + 0x14(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView + 0x76(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Syncfusion.Maui.Toolkit.SfViewHandler.SetVirtualView + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler + 0x7e(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler + 0xae(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Handlers.BorderHandler.UpdateContent + 0x53(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.PropertyMapper.UpdateProperties + 0x22(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView + 0xaf(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Handlers.BorderHandler.SetVirtualView + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler + 0x7e(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler + 0xae(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Platform.ViewExtensions.ToHandler + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.TemplateHelpers.GetHandler + 0x18(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.ItemContentView.CreateHandler + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.ItemContentView.RealizeContent + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.TemplatedItemViewHolder.Bind + 0x93(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.ItemsViewAdapter`2.BindTemplatedItemViewHolder + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.StructuredItemsViewAdapter`2.BindTemplatedItemViewHolder + 0x68(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.ItemsViewAdapter`2.OnBindViewHolder + 0x38(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.StructuredItemsViewAdapter`2.OnBindViewHolder + 0x56(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewAdapter`2.OnBindViewHolder + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.Handlers.Items.GroupableItemsViewAdapter`2.OnBindViewHolder + 0x4b(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at AndroidX.RecyclerView.Widget.RecyclerView+Adapter.n_OnBindViewHolder_Landroidx_recyclerview_widget_RecyclerView_ViewHolder_I + 0xe(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Java.Interop.JniEnvironment+StaticMethods.CallStaticLongMethod + 0x67(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.PlatformInterop.MeasureAndGetWidthAndHeight + 0x66(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler + 0x65(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Layouts.LayoutExtensions.ComputeDesiredSize + 0x0(Unknown Source)
05-25 03:24:50.233 AndroidRuntime: at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Measure + 0x0(Unknown Source)
05-25 03:24:50.239 ActivityTaskManager: Force finishing activity com.companyname.mauisamplecontentandroid/crc64240ecb5b7da1ec7e.MainActivity
05-25 03:24:50.241 ActivityManager: Showing crash dialog for package com.companyname.mauisamplecontentandroid u0
Mono Default (Pixel 8)
05-25 03:10:33.177 AndroidRuntime: FATAL EXCEPTION: main
05-25 03:10:33.177 AndroidRuntime: android.runtime.JavaProxyThrowable: [Microsoft.Maui.Platform.HandlerNotFoundException]: Unable to find a IElementHandler corresponding to Microsoft.Maui.Controls.CheckBox. Please register a handler for Microsoft.Maui.Controls.CheckBox using `Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.AddHandler` or `Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.TryAddHandler`
05-25 03:10:33.181 MonoDroid: Android.Runtime.JavaProxyThrowable: Exception_WasThrown, Android.Runtime.JavaProxyThrowable
NativeAOT CoreCLR (Pixel 8)
05-25 02:59:33.574 AndroidRuntime: FATAL EXCEPTION: main
05-25 02:59:33.574 AndroidRuntime: net.dot.jni.internal.JavaProxyThrowable: Microsoft.Maui.Platform.HandlerNotFoundException: Unable to find a IElementHandler corresponding to Microsoft.Maui.Controls.CheckBox. Please register a handler for Microsoft.Maui.Controls.CheckBox using `Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.AddHandler` or `Microsoft.Maui.Hosting.MauiHandlersCollectionExtensions.TryAddHandler`
Android framework version
net11.0-android (Preview)
Affected platform version
Microsoft.NET.Sdk.Android 36.99.0-ci.main.254, Microsoft.NET.Sdk.Maui 11.0.0-preview.4.26266.2, .NET runtime 11.0.0-preview.5.26269.119
Description
A MAUI 11 Android app generated from the
--sample-contenttemplate crashes during the first activity launch as soon as the initial page is realized. The failure reproduces across all three Android runtime flavors and only differs in the surface exception:System.TypeLoadException: the generic[ElementHandler<CheckBoxHandler>]attribute onMicrosoft.Maui.Controls.CheckBoxfails its constraint check at the point handler resolution materializes the attribute.Microsoft.Maui.Platform.HandlerNotFoundException: handler resolution returns no attribute, soMauiHandlersFactorycannot find a handler forCheckBox.HandlerNotFoundExceptionas Mono.All three crash on the main thread while binding a
CollectionViewitem template that contains aCheckBox, so the activity is force-finished and never reportsDisplayed/COLDto ActivityManager.Debug-configuration builds appear unaffected — this is observed only on
Release(and on NativeAOT, which is implicitly Release-like).A trivial MAUI Android app (
dotnet new mauiwithout--sample-content, noCheckBoxin the visual tree) launches and renders normally on the same workload and runtime, so the failure is specific to types that rely on the[ElementHandler<T>]attribute discovery path forCheckBox.Steps to Reproduce
rollback.jsonpins:microsoft.net.sdk.android = 36.99.0-ci.main.254 / 11.0.100-preview.5microsoft.net.sdk.maui = 11.0.0-preview.4.26266.2 / 11.0.100-preview.5am:Expected: app reaches first frame, ActivityManager logs
Displayed com.companyname.mauisamplecontentandroid/...MainActivity.Actual:
am start-activity -WreturnsLaunchState: UNKNOWN (0); logcat showsFATAL EXCEPTION: mainandActivityManager: Showing crash dialog for package com.companyname.mauisamplecontentandroid; noDisplayedline is emitted.Did you find any workaround?
None yet. Adding the missing handler registration manually (e.g.
handlers.AddHandler<CheckBox, CheckBoxHandler>()inMauiProgram.CreateMauiApp) avoids theHandlerNotFoundExceptionon Mono/NativeAOT, but theSystem.TypeLoadExceptionon CoreCLR still triggers when the attribute is enumerated.Relevant log output
CoreCLR Default (Pixel 8)
Mono Default (Pixel 8)
NativeAOT CoreCLR (Pixel 8)