Skip to content

[Trimming] Fix trimming unfriendly usage of implicit operators through reflection #19922

@simonrozsival

Description

@simonrozsival

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

  1. 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
  2. Globally disable trimming of implicit operators

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions