Bug in Removing Nested Types

11 views
Skip to first unread message

Lotfi

unread,
Mar 15, 2009, 6:29:05 AM3/15/09
to mono-cecil
Hy Jb,

Its seams that a removing a nested type from an assembly using Cecil
leads to corrupted metadata. Consider the simple following case :

class Class1
{
class Class2
{ }
}

Removing the class "Class1/Class2" would cause the metadata to be
corrupted !

AssemblyDefinition ad = AssemblyFactory.GetAssembly("CecilTest.exe");
ad.MainModule.Types.Remove(ad.MainModule.Types["Class1/Class2"]);

AssemblyFactory.SaveAssembly(ad, "CecilTest2.exe");

PEVerify prints :
[MD]: Error (Structural): Table=0x00000029, Col=0x00000000,
Row=0x00000001, has rid out of range.

Please help !

Jb Evain

unread,
Mar 15, 2009, 8:03:53 AM3/15/09
to mono-...@googlegroups.com
Hey,

On 3/15/09, Lotfi <gher...@gmail.com> wrote:
AssemblyDefinition ad = AssemblyFactory.GetAssembly("CecilTest.exe");
> ad.MainModule.Types.Remove(ad.MainModule.Types["Class1/Class2"]);

You'd also have to remove the class from the NestedTypes collection of
the declaring type.

--
Jb Evain <j...@nurv.fr>

Lotfi Gheribi

unread,
Mar 15, 2009, 8:23:39 AM3/15/09
to mono-...@googlegroups.com
Works great, thanks !
Reply all
Reply to author
Forward
0 new messages