Description
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.