Skip to content

Linker should recognize GetType() on sealed local variables #1218

@eerhardt

Description

@eerhardt

When passing in variable.GetType() into a method that is annotated with DynamicallyAccessedMembers, the linker should be able to statically infer the Type if the Type of the variable is sealed. However, the linker is not preserving the correct members on the Type in this situation.

For example,

    public class TraceLoggingEventTypes
    {
        internal TraceLoggingEventTypes(
            string name,
            EventTags tags,
            [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
...
    var msg = new { message = msgString };
    var tlet = new TraceLoggingEventTypes(EventName, EventTags.None, msg.GetType());

When linking code like the above, the message property is getting trimmed from the anonymous type.

See my attempted code change for this scenario in EventSource.

cc @vitek-karas @MichalStrehovsky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions