JohnAustin
JohnAustin
CC#
Created by JohnAustin on 4/7/2024 in #help
Accessing private methods when using Reflection.Emit and AssemblyBuilder
I am writing a compiler that runs in process, and generates IL on the fly to speed up various execution graphs in our code. For convenience we allow users to call private static functions within the generated code. I have been using DynamicMethod to emit IL, which allowed emitting calls to private methods. However, after swapping over to a more standard AssemblyBuilder approach, I'm getting MethodAccessExceptions in the generated IL code. Are emitted dynamic assemblies more strict than DynamicMethods? It seems like an arbitrary distinction, as both are emitted into the same domain, and not written to disk. Is there a good way to get around MethodAccessException, or do I have to stick with DynamicMethod only?
4 replies