How to replace a class in dll?

The topic is rather vague, since I donโ€™t know what the correct terminology is for what I'm trying to do.

I downloaded the dll (I donโ€™t have the source code) and using the reflection tool I found an error in the dll implementation. The error is easy to fix. So let's say the error is here:

 class A { void f() { // BUG!!! } } 

Is there a way to implement my own A , which will fix the error and introduce it at runtime to replace other instances of A ?

+45
c # dll
Feb 25 '14 at 12:38
source share
2 answers

If you are using .NET 4.0. or higher, look at: MethodRental.SwapMethodBody method

Another way: CLR Injection: Runtime Reagent

+71
Feb 25 '14 at 12:41
source share

The easiest way is to inherit from this class and write your own implementation.

  class ParentClass { public void SomeMethod() { //bug here } } class Child:ParentClass { new public void SomeMethod() { // I fixed it } } 

Here, use your class.

 Child child = new Child(); child.SomeMethod(); 
+8
Feb 25 '14 at 12:48
source share



All Articles