[net11.0] Workaround #35665: use DI handler registration for CheckBox#35666
Conversation
The `[ElementHandler<CheckBoxHandler>]` attribute on CheckBox causes handler resolution to fail on .NET 11 preview Android Release builds (TypeLoadException on CoreCLR, HandlerNotFoundException on Mono/NativeAOT). As a temporary workaround, remove the attribute from CheckBox (the only type using it) and register the handler via the regular DI path. The ElementHandler attribute mechanism will be reworked in #29952. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35666Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35666" |
Correction + verified root-cause analysisMy earlier comment was wrong on the mechanism and I'm correcting it. Specifically, the claim that " What is actually verified
Why this workaround is correct regardless of the exact low-level causeRe-adding cc @ apologies for the earlier inaccurate mechanism description. |
Root cause confirmed: net11 ILLink trimmer regression → filed dotnet/runtime#128756I built a minimal standalone reproduction that isolates the crash down to a trimmer bug, independent of MAUI. What the bug isThe net11 trimmer removes the public parameterless constructor of a type that is used only as the generic argument of a That's exactly our Minimal repro (no MAUI)using System;
using Repro;
typeof(CheckBox).GetCustomAttributes(false);
Console.WriteLine("RESULT: OK");
namespace Repro
{
public class Handler { }
class MyAttribute<T> : Attribute where T : new() { }
[My<Handler>] class CheckBox { }
}
Confirmed it's a regression (same source, same trim settings)
Two independent mitigations confirm the mechanism: removing Why this workaround PR is correct
Filed upstreamTrimmer bug filed at dotnet/runtime#128756. The full trim/AOT-safe rework of the handler attributes is tracked separately in #29952.
|
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Workaround for #35665.
The
[ElementHandler<CheckBoxHandler>]attribute onCheckBoxcauses handler resolution to fail on .NET 11 preview MAUI templates on Android Release builds across all runtime flavors:System.TypeLoadExceptionwhen the generic attribute is enumerated (GenericArguments[0] ... violates the constraint of type parameter 'THandler').HandlerNotFoundException, since the attribute isn't found and no DI registration exists.CheckBoxwas the only type using[ElementHandler<T>]. This PR removes the attribute and restores the regular DI handler registration (AddHandler<CheckBox, CheckBoxHandler>()), which unblocks the failing template builds.The
[ElementHandler<T>]attribute mechanism itself will undergo a major refactoring in #29952, so this is intentionally a minimal, targeted workaround rather than a fix of the attribute path.Issues Fixed
Fixes #35665