Open rockfordlhotka opened 1 year ago
I am working on this.
@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.
Best process in my experience how to annotate project for AOT is following
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.
@kant2002 any progress on this effort?
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