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

Reflection access from Pinvokes and InternalCalls should warn at callsite #2188

Closed
sbomer opened this issue Aug 3, 2021 · 2 comments
Closed

Comments

@sbomer
Copy link
Member

sbomer commented Aug 3, 2021

Currently when the linker sees a PInvoke or InternalCall that is an instance method it preserves all fields of the declaring type: https://github.com/mono/linker/blob/762278c9c3e60f5a82733dc0386bd0cf7f0a2d22/src/linker/Linker.Steps/MarkStep.cs#L3266

This produces warnings if any of the fields is annotated. Would it make more sense to warn at the callsites to the interop method? Currently the origin is the interop method itself, which is unusual in cases where the required fields depend on the callsite - see dotnet/runtime#56593 (comment).

@MichalStrehovsky @LakshanF

@MichalStrehovsky
Copy link
Member

This is not a user scenario - it's some quirk for Mono.

P/invoke cannot be an instance method on CoreCLR and InternalCall is only used on COM classes that cannot have fields anyway. You'll get a TypeLoadException on this with CoreCLR.

I don't think we need to bother with this scenario.

@sbomer
Copy link
Member Author

sbomer commented Aug 4, 2021

Thanks! Closing.

@sbomer sbomer closed this as completed Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants