MAUI uses implicit operators invoked via reflection in several places, for example:
Unfortunately, this pattern isn't trimming/AOT compatible and we cannot fix it with [DynamicallyAccessedMembers] (in some cases the type isn't known at compile time, such as in value.GetType().GetImplicitConversionOperator(...)). When app code is trimmed, some of the required implicit conversion operators might not be available at runtime leading to unexpected behavior.
Related to #18658, /cc @jonathanpeppers
Trimming warnings related to this issue are tracked in #19397
Possible solutions
- Make the use of implicit operators obsolete and replace them with a different mechanism, such as
IValueConverter
- we could still keep the existing code with implicit operators, but it would be the responsibility of the developers to ensure the implicit operators are preserved by the trimmer using
[Preserve] or [DynamicDependency]
- this would be a breaking change to some apps
- Globally disable trimming of implicit operators
MAUI uses implicit operators invoked via reflection in several places, for example:
BindableProperty.TryConvert(...)BindableObject.SetValue(...)is usedStaticResourceExtension.ProvideValue(...)Unfortunately, this pattern isn't trimming/AOT compatible and we cannot fix it with
[DynamicallyAccessedMembers](in some cases the type isn't known at compile time, such as invalue.GetType().GetImplicitConversionOperator(...)). When app code is trimmed, some of the required implicit conversion operators might not be available at runtime leading to unexpected behavior.Related to #18658, /cc @jonathanpeppers
Trimming warnings related to this issue are tracked in #19397
Possible solutions
IValueConverter[Preserve]or[DynamicDependency]