icktoofay
icktoofay

Reputation: 129011

Replacing a class with Mono.Cecil

Say I have assembly A. It was modified with Mono.Cecil a little bit. Now say I have assembly B. It has a class named SomeClass. Assembly A also has a class named SomeClass. Now I want to replace SomeClass from assembly A with the one in assembly B. I tried a few things, but I know that for one of my attempts, it actually remapped a method call like this:

Console.WriteLine("Test.");

...into this:

int.WriteLine("Test.");

That can't be right. What is the correct way to replace a class with Mono.Cecil?

Upvotes: 2

Views: 937

Answers (1)

Jb Evain
Jb Evain

Reputation: 17499

You're probably doing something that Cecil doesn't understand. It's impossible to tell you what without seeing any code.

Swapping a type by another is not trivial, you'd have to recreate in the target module the object model you want to inject, and replace every reference of it with the new one. Basically, you'd have to walk over every reference in the target module and make sure it's properly processed.

Upvotes: 1

Related Questions