Closed lxy-iUnknown closed 1 day ago
Thanks for submitting this. The better change would be to replace LibLog with MS's logging extensions. I'm not opposed to that but it's not something I'll be able to take on soon.
Even with that work, I'm not sure CommandDotNet is AOT friendly given it relies heavily on reflection to generate the commands and none of that work is currently persisted with source generators. It's something that would be very useful if someone had the time to submit a PR for it.
Thanks for submitting this. The better change would be to replace LibLog with MS's logging extensions. I'm not opposed to that but it's not something I'll be able to take on soon.
Even with that work, I'm not sure CommandDotNet is AOT friendly given it relies heavily on reflection to generate the commands and none of that work is currently persisted with source generators. It's something that would be very useful if someone had the time to submit a PR for it.
Thanks for your reply. I've made a working AOT example. NativeAotSample.zip
Currently, Native AOT does not support method subsitution if its return type is not bool or int
So I modified CommandDotNet binary by replacing "GetLogger(stackFrame.GetMethod().DeclaringType);" to "GetLogger(stackFrame.GetMethod()?.DeclaringType);"
DynamicDependencyAttribute and rd.xml are also necessary.
Thanks @lxy-iUnknown is your sample in a public repo by chance? I'm leery of zip files.
when you modified the GetLogger call, did that change the type used for the logger name?
@drewburlingame I published to github recently. NativeAotSample I only modified the method body using dnSpyEx, not type name. Everything remain unchanged except for this method
I removed usages of GetCurrentClassLogger which called the code you modified with dnSpyEx. It was simpler than removing LibLog. Given the high level of reflection used, I'm still not sure how AOT is safely removing code, but this should satisfy your use case.
Root cause: LibLog uses StackFrame.GetMethod to create logger from caller class, which is null in native aot environment. See: Native AOT StackFrame method info [API Proposal]: Diagnostic method information Solution: Replace with nameof