Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eiriktsarpalis opened this issue Feb 4, 2025 · 4 comments
Labels
area-System.Runtime linkable-framework Issues associated with delivering a linker friendly framework untriaged New issue has not been triaged by the area owner

Comments

@eiriktsarpalis
Copy link
Member

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 4, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 4, 2025
@stephentoub
Copy link
Member

Very similar to the discussion here:
#89002 (comment)

@eiriktsarpalis eiriktsarpalis added area-System.Runtime untriaged New issue has not been triaged by the area owner linkable-framework Issues associated with delivering a linker friendly framework and removed untriaged New issue has not been triaged by the area owner needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 4, 2025
Copy link
Contributor

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@Sergio0694
Copy link
Contributor

We hit this in a few places in the Store as well. Glad to see there seems to be an increase in interest in this 😄
@teo-tsirpanis' suggestion in #89002 (comment) seems interesting, assuming it's doable...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime linkable-framework Issues associated with delivering a linker friendly framework untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants