The subject is pretty vague since I'm not sure what's the correct terminology for what I'm trying to do.
I've downloaded a dll
(I don't have the source code), and using a reflection tool, I found a bug in the dll
implementation. The bug is easy to fix. So let's say the bug is here:
class A { void f() { // BUG!!! } }
Is there any way to implement my own A
which would fix the bug and inject it in runtime to replace other A
instances?
We can create new methods in the dll library class also without changing the old code though extension method. Let's see the simple example of extensionmethod . return (a + " " + b); // This is the extension method named Myextmethod.
Search for your class name in the object browser (Menu View -> Object Browser). The assembly information window will contain the dll complete path. Show activity on this post.
Using libraries is useful when you want to share code between multiple programs. If you think you will need your classes to sanitize data in more than one program, this is a good idea to put them in a library.
A class library defines types and methods that are called by an application. If the library targets . NET Standard 2.0, it can be called by any . NET implementation (including . NET Framework) that supports .
If you are using .NET 4.0. or higher, take a look at the: MethodRental.SwapMethodBody Method
Other way: CLR Injection: Runtime Method Replacer
Easiest way would be to inherit from that class and write your own implementation.
class ParentClass { public void SomeMethod() { //bug here } } class Child:ParentClass { new public void SomeMethod() { // I fixed it } }
Here after, use your class.
Child child = new Child(); child.SomeMethod();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With