class 02000002 is nested in missing class 02000001

Topics: Metadata Model
Jan 4, 2011 at 6:35 AM
Edited Jan 4, 2011 at 6:38 AM

I'm getting few errors like 

class 02000002 is nested in missing class 02000001

from ildasm when I open an assembly that I generated with CCI-Metadata.

All nested types and methods of that (static) class are displayed as namespace members in by ildasm (I mean: at the same tree level of the other namespace type, which is unusual for methods).

Also two methods are missing at runtime and for peverify.

[IL]: Error: [\StorageImpl.dll : Implementation+ReadInstanceFromArchive-Closure-ClassLibrary1.Person::Read][mdToken=0x6000020] Method does not exist.

[IL]: Error: [\StorageImpl.dll : Implementation+ReadStructFromArchive-Closure-ClassLibrary1.Color::Read][mdToken=0x6000022] Method does not exist.

Reflector shows all correctly in place.

Do you have any idea of what could cause this?

Jan 4, 2011 at 6:13 PM

I removed as much as I can from the assembly. Now I get Ildasm saying the methods are global:

//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1
//  Copyright (c) Microsoft Corporation.  All rights reserved.



// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern ClassLibrary1
{
  .ver 1:0:0:0
}
.assembly StorageImpl
{
  .hash algorithm 0x00008004
  .ver 1:0:0:0
}
.module StorageImpl.dll
// MVID: {BE0FE2BA-9059-4065-9EB7-BBACE2AC4C4E}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x002C0000


// ================== GLOBAL METHODS =========================

.method public hidebysig static void  Write(class [ClassLibrary1]ClassLibrary1.Person self,
                                            class [mscorlib]System.IO.BinaryWriter writer) cil managed
{
  // Code size       25 (0x19)
  .maxstack  8
  IL_0000:  ldarg.1
  IL_0001:  ldarg.0
  IL_0002:  callvirt   instance string [ClassLibrary1]ClassLibrary1.Person::get_Name()
  IL_0007:  callvirt   instance void [mscorlib]System.IO.BinaryWriter::Write(string)
  IL_000c:  ldarg.1
  IL_000d:  ldarg.0
  IL_000e:  callvirt   instance int32 [ClassLibrary1]ClassLibrary1.Person::get_Age()
  IL_0013:  callvirt   instance void [mscorlib]System.IO.BinaryWriter::Write(int32)
  IL_0018:  ret
} // end of global method Write

.method public hidebysig static void  Write(valuetype [ClassLibrary1]ClassLibrary1.Color self,
                                            class [mscorlib]System.IO.BinaryWriter writer) cil managed
{
  // Code size       40 (0x28)
  .maxstack  8
  IL_0000:  ldarg.1
  IL_0001:  ldarga.s   self
  IL_0003:  call       instance float64 [ClassLibrary1]ClassLibrary1.Color::get_Red()
  IL_0008:  callvirt   instance void [mscorlib]System.IO.BinaryWriter::Write(float64)
  IL_000d:  ldarg.1
  IL_000e:  ldarga.s   self
  IL_0010:  call       instance float64 [ClassLibrary1]ClassLibrary1.Color::get_Green()
  IL_0015:  callvirt   instance void [mscorlib]System.IO.BinaryWriter::Write(float64)
  IL_001a:  ldarg.1
  IL_001b:  ldarga.s   self
  IL_001d:  call       instance float64 [ClassLibrary1]ClassLibrary1.Color::get_Blue()
  IL_0022:  callvirt   instance void [mscorlib]System.IO.BinaryWriter::Write(float64)
  IL_0027:  ret
} // end of global method Write

.method assembly hidebysig static void  'Write-ClassLibrary1.Person'(object self,
                                                                       class [mscorlib]System.IO.BinaryWriter writer) cil managed
{
  // Code size       13 (0xd)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  unbox.any  [ClassLibrary1]ClassLibrary1.Person
  IL_0006:  ldarg.1
  IL_0007:  call       void Write(class [ClassLibrary1]ClassLibrary1.Person,
                                  class [mscorlib]System.IO.BinaryWriter)
  IL_000c:  ret
} // end of global method 'Write-ClassLibrary1.Person'

.method assembly hidebysig static void  'Write-ClassLibrary1.Color'(object self,
                                                                      class [mscorlib]System.IO.BinaryWriter writer) cil managed
{
  // Code size       13 (0xd)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  unbox.any  [ClassLibrary1]ClassLibrary1.Color
  IL_0006:  ldarg.1
  IL_0007:  call       void Write(valuetype [ClassLibrary1]ClassLibrary1.Color,
                                  class [mscorlib]System.IO.BinaryWriter)
  IL_000c:  ret
} // end of global method 'Write-ClassLibrary1.Color'


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************

 

And Reflector saying (as expected) that there is a class that contains the methods:

.class public abstract auto ansi sealed beforefieldinit Implementation
    extends [mscorlib]System.Object
{
    .method public hidebysig static void Write(valuetype [ClassLibrary1]ClassLibrary1.Color self, class [mscorlib]System.IO.BinaryWriter writer) cil managed
    {
    }

    .method public hidebysig static void Write(class [ClassLibrary1]ClassLibrary1.Person self, class [mscorlib]System.IO.BinaryWriter writer) cil managed
    {
    }

    .method assembly hidebysig static void Write�ClassLibrary1.Color(object self, class [mscorlib]System.IO.BinaryWriter writer) cil managed
    {
    }

    .method assembly hidebysig static void Write�ClassLibrary1.Person(object self, class [mscorlib]System.IO.BinaryWriter writer) cil managed
    {
    }

}

I checked the CCI objects: my methods definition have that type as containing type, the assembly includes that type in GetAllTypes().

 

Coordinator
Jan 4, 2011 at 6:17 PM

ILDasm seems to think that your Write methods are members of the special "<Module>" class that must be the first class in every assembly.

Jan 4, 2011 at 6:38 PM
Edited Jan 4, 2011 at 6:41 PM

Thanks.

I think in my more recent assemblies I forgot to add a module class.

I may have worked like this for months without any trouble.

Probably I'll add a ModuleClass abstract property to my IAssembly abstract implementations from now on, so that it's not possible to do that again.

Having a special ModuleClass property in your metadata model would help too, unless you see other problems.

Jan 4, 2011 at 8:04 PM

Actually I already did that months ago but I inadvertently excluded that module class with an awkward method overload.