Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is IL Weaving?

Tags:

.net

postsharp

Weaving refers to the process of injecting functionality into an existing program. This can be done conceptually at a number of levels:

  • Source code weaving would inject source code lines before the code is compiled
  • IL weaving (for .NET) adds the code as IL instructions in the assembly
  • ByteCode weaving (for Java) works on the class file, see these comments wrt AspectJ

In theory you could go one deeper and weave with an executable compiled to native instructions, but this would add a lot of complexity and I'm not aware of anything that does this.


IL Weaving is simlar to ByteCode Weaving. .Net compiles to an intermediate language which is run by the .NET clr. IL Weaving is basically analyzing and altering the intermediate language. Since it is done at that level it can be done for all .NET languages.


Might help if you Google MSIL Injection instead. This link is from PostSharp and it explains it well.

My company has recently bought a product called dynaTrace for performance diagnosis. It uses MSIL injection to instrument around methods. Basically it adds IL code before your method and after to time the method (I am sure there is a lot more to it than that).

And here is a fairly involved but good explanation of the process.