ASP.NET Hosting

Patcher: easy assembly patching

This is an idea I had some time ago. I think this picture speaks by itself:

The idea is about a tool that would allow easily patching code (remove, add, update).

Typical scenario: you have this DLL (assembly) you'd like to modify to add some tracing code, but you don't want to (or can't) go back to the source code.
You can also think of this as Edit&Continue for every assembly...



  • I have an idea for another add-in for Reflector: populating an agent (perhaps using a WMI provider). This can then be read remotely and also by other Sys Mgmnt tools.

    I had started on it about a year ago but current client projects have kept me too occupied and away from it. I'll revisit sometime soon.

  • You are really approaching the domain of aspect oriented programming with what you are suggesting. True AOP uses the concept of a joinpoint and pointcut composition to provide the ability to find and inject cross-cutting code (e.g. tracing falls into the realm of cross-cutting concerns) at a specific point in code. Take a look at's a java implementation but it does exactly what you are talking about at compile time by modifying the compilation process. by creating their own compiler they were able to extend the java language to support cross-cutting concerns.

    -Mathew Nolton

  • Sorry this comment has been posted first in the Read More.


    Here are some thoughts,

    It should be a bit more difficult if you plan to work in high level languages traduced by Reflector.

    If you work with IL :

    Should be easier to do. We can modify instructions, all we have to do is to ensure that branches are still valid. But not everyone read IL as they read C# or VB.Net.

    Then, all we have to do is to generate the modified method using Emit or Rail.

    If you plan to work in a high level language :

    You have to parse the modified code (Using CodeDom ?), compile it, then substitute the modified assembly's members in the targeted assembly. It should be done using Rail. Note that code produces by Reflector is sometimes a little tricky, I hope that CodeDom will be able to parse it.

    You just have to know that Emit is painful, and that Rail is very slow and not optimized for the moment, and it is still in early stage of development, do not expect to load assemblies like System.Web. Note that Rail acts as a decompiler too (maybe the more complete for a free, open source and available product).

    All of that would have been a lot easier if System.Reflection.* was complete.

    Please note that it will be easier too if Microsoft would release it's CCI assembly (the one used by FxCop to read assemblies).

    Evain Jb,

    AspectDNG co-developer

    Rail contributor

Comments have been disabled for this content.