❔ how do i print the bytecode generated from a ILGenerator? (im getting an error)
i am trying to generate and print csharp bytecode using
ILGenerator
and AssemblyBuilder
, ModeuleBuilder
, etc, but when i try to get my bytecode using the code below, i get the following error:
my code:
PS, i have no clue if this is beginner, intermediate, or advanced (and im likely in way over my head here)13 Replies
Is the error from
GetMethodBody
or GetILAsByteArray
?getMethodBody
i tried looking it up and it might be that the method doesnt have a body, but the only way i can find to give it a body is exactly what im doing hereMethodBuilder
does not seem to provide an override for GetMethodBody
, and none is provided by any of its base types
so it throws an exception
what's your use case for generating IL? there may be a better APIits the compiled result of a programming language im writing
are you very familiar with IL? I have worked on something similar where I just manually generated the IL
not at all
i was having a lot of trouble trying to learn how to generate it manually, because i could only find code like this
i was hoping that being able to print the result would help me learn
if you have any rescources or advice for generating it manually i would appreciate it
https://www.codeproject.com/Articles/3778/Introduction-to-IL-Assembly-Language
this is what I used to learn how IL works
there are also a couple of really annoyingly difficult to find tools for verifying and compiling IL into an executable
CodeProject
Introduction to IL Assembly Language
Start using IL Assembly Language to debug your code at low level and understand how .NET deals with your high level code
PEVerify or ILVerify for verifying an executable/dll
ILAsm for compiling executables/dlls
IL is object oriented and you can use the
mscorlib
for string operations (and various other things)ok tysm!
if you run into any specific problems or have questions feel free to dm or reply here (for as long as this thread will be open)
ok thanks i appreciate it
idk how long i have rn but i may post anothger thread some other time
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.