© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
64 replies
blue

❔ Loading arbitrary values onto a ILGenerator stack

hey! i'm new to c# and i have a question/issue regarding the ILGenerator.

I am trying to use a function from JS to subscribe to an event handler. What I came up with was extracting the correct argument types using Reflection (from the target event's
Invoke
Invoke
function) and then creating a
DynamicMethod
DynamicMethod
to call the JS function, using
ILGenerator.EmitCall
ILGenerator.EmitCall
.
After hours of trying to do this, I noticed something: calling the JS function requires 3 arguments (first one being null), but I only have 2.
Is there a way to load a null value to
Ldarg_0
Ldarg_0
without messing with the arguments of the dynamic method? I took a look at the
Opcodes
Opcodes
class (not everything obv) and couldn't find any load operations related to that. any suggestions are appreciated because I really don't know what to do now 🙃
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
Next page

Similar Threads

Previewing IL generated by ILGenerator
C#CC# / help
3y ago
✅ ILGenerator Object Mapper Property Set
C#CC# / help
3y ago
Using ILGenerator to create and populate a List<string>
C#CC# / help
3y ago
Downloading a file onto a project
C#CC# / help
3y ago