6

How can I dynamically modify MSIL code in-memory with C#/.NET?

And yes, I'm really looking to replace existing code that's already in memory on the fly.
Specifically, I'm not:

  • Looking to only generate new code (via expression templates, ILGenerator, etc.)
  • Trying to emit a new binary module in the hopes of loading it into memory later
user541686
  • 205,094
  • 128
  • 528
  • 886
  • As far as I am aware, this is not supported in .net IL. Why is this specific scenario required? – flacnut Jul 01 '13 at 23:26
  • Why do you need this? – It'sNotALie. Jul 01 '13 at 23:35
  • @newStackExchangeInstance: I can't really discuss the project I'm working on, all I can say is that having this capability would help a lot. – user541686 Jul 01 '13 at 23:51
  • @sheldo Given that Mehrdad is talking about a Virtual Machine Runtime, whose premise of an easily modifiable IL comes with the .NET territory, it is definitely possible. Additionally with `unsafe` and/or Marshalled invocations there is little one can not do. – Lorenz Lo Sauer Sep 27 '13 at 08:11

1 Answers1

2

.Net Profiling API seems promising.

Otherwise, I'm stumped.

mbx
  • 6,292
  • 6
  • 58
  • 91
Mentok
  • 597
  • 4
  • 6