Hey guys,
First of all, I love Mono.Cecil, it's a really awesome library!
Thanks!
I'm writing a small utility which essentially takes an exe, searches
up its dll dependencies (ignores the ones from the .NET Framework),
and copies everything from the dlls to the exe (only what is used).
Everything works perfectly, until there is a custom delegate type, in
which case the program crashes with a NullReferenceException in
Mono.Cecil when the modified assembly is being written to the disk.
The exception occurs in Mono.Cecil.Cil.CodeReader.MoveTo:
public void MoveTo (int rva)
{
if (!IsInSection (rva)) {
code_section = reader.image.GetSectionAtVirtualAddress ((uint) rva);
Reset (code_section.Data); // here, code_section is null, rva is 0
}
base.position = rva - (int) code_section.VirtualAddress;
}
Looking up the stack trace, the method being processed is the
constructor of the custom delegate type:
System.Void MyNamespace.TestDelegate..ctor(System.Object,
System.IntPtr)
I'm not modifying (in fact, not even inspecting) the delegate type,
just cloning it as is and adding it to the exe assembly.
Any ideas on how to solve this, or at least work around it?
Thank you very much!
--
--
mono-cecil