-
Notifications
You must be signed in to change notification settings - Fork 491
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
Since updating to .NET 10 (MAUI 10.0.41), applications using CommunityToolkit.Maui.MediaElement crash on Android when trimming is enabled. The trimmer is incorrectly identifying essential constructors and JNI-callback methods as unused code and stripping them.
Expected Behavior
The MauiMediaElement should survive the .NET 10 trimming process so that the Android OS can properly invoke its constructors during lifecycle events (like OnDetachedFromWindow or XAML inflation) without throwing a MissingMethodException.
Steps To Reproduce
- Create a MAUI project targeting net10.0-android.
- Add CommunityToolkit.Maui.MediaElement v8.0.0.
- Configure the .csproj with the following aggressive trimming settings:
<PropertyGroup Condition="$(TargetFramework.Contains('-android'))">
<AndroidLinkMode>Full</AndroidLinkMode>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
</PropertyGroup>
- Navigate to a page containing a MediaElement.
Link to public reproduction project repository
https://github.com/kizwiz6/MauiBug
Environment
- .NET MAUI CommunityToolkit: 8.0.0
- OS: Windows 11
- .NET MAUI: 10.0.41
- Link Mode: Full
- Trim Mode: partial (Full trim mode causes even deeper XAML parser failures)Anything else?
Crash Log Evidence:
The following stack trace was captured by wrapping InitializeComponent() in a diagnostic try-catch. It confirms the trimmer has removed the constructor:
=== TRIMMER CRASH DETECTED ===
Microsoft.Maui.Controls.Xaml.XamlParseException: Position 15:10. Arg_NoDefCTor, CommunityToolkit.Maui.Views.MediaElement
---> System.MissingMethodException: Arg_NoDefCTor, CommunityToolkit.Maui.Views.MediaElement
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
Workarounds Attempted (and Failed):
In a separate and larger production project, the following attempts were made to preserve the types, but the .NET 10 trimmer ignored them:
- Added
<TrimmerRootAssembly Include="CommunityToolkit.Maui.MediaElement" /> - Added explicit Linker.xml descriptors for the MauiMediaElement type.
- Added proguard.cfg rules.
Result: The app still crashes with MissingMethodException (regarding Media3 listeners) or AbstractMethodError (regarding constructors).