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

Add RequiresDynamicCode attribute to dynamic methods/members #3347

Open
rockfordlhotka opened this issue May 19, 2023 · 4 comments
Open

Add RequiresDynamicCode attribute to dynamic methods/members #3347

rockfordlhotka opened this issue May 19, 2023 · 4 comments

Comments

@rockfordlhotka
Copy link
Member

Generally speaking, CSLA will not work with ahead-of-time compilation (AOT) because it makes use of unbounded generic types, reflection, expression trees, and other features that are incompatible with AOT.

To be a good citizen, we should mark methods that build expressions, use reflection, etc. with the RequiresDynamicCode attribute.

https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/fixing-warnings

@Freelancingonupwork
Copy link
Contributor

I am working on this.

@rockfordlhotka
Copy link
Member Author

@Freelancingonupwork let us know (here or in discord) if you have questions. I suspect this issue will require some research and experimentation - at least it would for me, as I haven't explored the AOT stuff in .NET yet.

The core of the issue here, is that AOT will "optimize" code that it thinks isn't being called, so the compiler literally removes the code from the compiled output. My understanding is that there are attributes that we can apply to the code to tell AOT that the code should be kept as part of the compiled output, even if it would normally have been optimized away.

I kind of suspect this will also affect business classes. For example, all the data portal operation methods (like [Create] private void Create() will appear to not be invoked by any other code, and so I am pretty sure AOT will optimize away all those methods. Obviously that's a problem, and so business developers will probably need to put an attribute on the data portal operation methods to keep them as part of the compiled output.

@kant2002
Copy link
Contributor

Best process in my experience how to annotate project for AOT is following

  • Enable AOT analyzer
  • Have WarningsAsErrors enabled (not nescessary, but nag you if you miss things)
  • List all AOT warnings in the NoWarn property.

Now after recording all work, you diligently find most trivial warnings which you can completely eliminate from the list.
once done, remove that warning from the NoWarn and nevel let it appear again.

RequiresDynamicCode should be probably last resort, there usually possibility to solve warnings based on context. Maybe it require some refactoring, maybe some shaking of code.

Example of how legacy codebases did that https://github.com/dotnet/SqlClient/pull/1959/files#diff-844a96fe684c7aecaa27e22d292e57d4418d2c9c591b62dcf4b0a4f90d918bb1R22
They are SUPER SLOW 😄 unfortunately.

@rockfordlhotka
Copy link
Member Author

@kant2002 any progress on this effort?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants