Skip to content

The T in Lazy<T> is marked DynamicallyAccessedMemberTypes.PublicParameterlessConstructor #112128

Open
@eiriktsarpalis

Description

@eiriktsarpalis

This is presumably there to support the default constructor which instantiates default instances via the Activator, but it creates false positives in AOT compatible projects consuming Lazy<T> without using reflection. For example, the following method issues a warning:

static Lazy<T> Create<T>(Func<T> factory) => new(factory);

forcing authors to either suppress the warning or virally add DynamicallyAccessedMemberTypes annotations to every generic method consuming Create. I'm not aware of any workarounds other than marking the default constructor as RequiresUnreferencedCode but presumably this would create regressions in trimmed apps using the default constructor. I'm wondering if there's a way we could specify DynamicallyAccessMembers on a type parameter in a way that is scoped to a particular constructor overload.

cc @vitek-karas @eerhardt for thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Runtimelinkable-frameworkIssues associated with delivering a linker friendly frameworkuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions