Jb Evain wrote:
On Tue, Nov 15, 2011 at 6:09 PM, [email protected]
<[email protected]>  wrote:
How can I copy a type from one assembly to another, currently I'm
doing this:

var t = assemblyDefA.MainModule.GetType("some name");
assemblyDefB.MainModule.Types.Add(t);

but I get "Type already attached".

Basically, you can't attach an existing instance (type, method, etc.) that has already been attached to one assembly to a new assembly. You have to clone the object instead, (deep-)copying its full state, which is what we do in il-repack. The cloning methods are *not* part of cecil itself: like Jb wrote, it involves taking decisions about the references and we know these decisions in il-repack (where we know which types to merge and which not to).

Simon

--
--
mono-cecil

Reply via email to