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

Marshal.PtrToStructure support in reflection free Native AOT #70837

Closed
Fabi opened this issue Jun 16, 2022 · 4 comments
Closed

Marshal.PtrToStructure support in reflection free Native AOT #70837

Fabi opened this issue Jun 16, 2022 · 4 comments

Comments

@Fabi
Copy link

Fabi commented Jun 16, 2022

Hey,

while working on a project/lib and tried to make it reflection free I noticed that Marshal.PtrToStructure actually throws "Reflection_Disabled" due to it's usage of Activator.CreateInstance. Marshal.StructureToPtr works fine though.

That makes functions like NetworkInterface.GetAllNetworkInterfaces that result in SystemNetworkInterface.GetNetworkInterfaces calls unusable in reflection free mode.

Are there any plans to fix that or any (safe) alternatives?

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 16, 2022
@Fabi Fabi changed the title Marshal.PtrToStructure support in Native AOT Marshal.PtrToStructure support in reflection free Native AOT Jun 16, 2022
@jkotas
Copy link
Member

jkotas commented Jun 16, 2022

We have no plans to make Marshal.PtrToStructure work in reflection-free mode. Duplicate of #67193.

However, we are usually happy to take PRs to eliminate Marshal.PtrToStructure usage and replace it with manual marshalling that is typically faster and less error prone.

@jkotas jkotas closed this as completed Jun 16, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 16, 2022
@Fabi
Copy link
Author

Fabi commented Jun 16, 2022

We have no plans to make Marshal.PtrToStructure work in reflection-free mode. Duplicate of #67193.

However, we are usually happy to take PRs to eliminate Marshal.PtrToStructure usage and replace it with manual marshalling that is typically faster and less error prone.

But isn't this just due to the non generic Activator.CreateInstance usage? The generic one works due to the analyzer catching it and keeping data for it. There is no switch that let us keep data for the non generic function (which calls the non generic one and really not more)

@jkotas
Copy link
Member

jkotas commented Jun 17, 2022

Marshal.PtrToStructure cannot just use the generic Activator.CreateInstance. Marshal.PtrToStructure allows private constructors that the generic Activator.CreateInstance disallows. Implementing a special version of the generic Activator.CreateInstance just to make this legacy API work in reflection-free mode is not worth it.

@jkotas
Copy link
Member

jkotas commented Jun 17, 2022

I have fixed up PtrToStructure instances you have mentioned and a few more in #70866

@ghost ghost locked as resolved and limited conversation to collaborators Jul 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants