© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
JohnAustin

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
MethodAccessException
MethodAccessException
s 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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Comparing types when using reflection
C#CC# / help
4y ago
❔ Invoking internal methods without reflection?
C#CC# / help
3y ago
Testing private methods
C#CC# / help
3y ago
Using reflection to build a dictionary of methods -> attributes at runtime
C#CC# / help
3y ago