Minor change to allow Native AOT compilation#113
Merged
Conversation
…mbly() to allow Native AOT in .NET 8 and above.
pavkam
approved these changes
Sep 26, 2025
pavkam
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR. You're right, the choice of the method to get the assembly is not important. I just used the first that came to mind. 🫡
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'd really like to be able to take advantage of the Native AOT compilation feature in .NET 8 and up when using Sharpie. Apparently the one blocker is a single use of
Assembly.GetCallingAssembly()inNativeLibraryWrapper.GetCallingAssembly()is kinda weird. It returns the assembly of the method that calls the method that then calls it. I don't know what dark magic it uses to achieve this, but it isn't supported when using Native AOT. However, the way it's being used in this project (inside a private method which is only called from within the same assembly) it always* returns the same result, which is the Sharpie assembly itself. So this PR replaces that call withGetExecutingAssembly()which returns the same result but doesn't have the same restrictions when used with Native AOT compilation.Native AOT seems to work fine after this change.
*Apparently there are edge cases where
GetCallingAssembly()will return a different result depending on how the compiler does inlining, but this doesn't seem to happen and I doubt it's the expected behavior in this case.