Metadata Validity Rules

Metadata Validity Rules

Recall that the type-related metadata tables include the TypeDef, TypeRef, InterfaceImpl, NestedClass, and ClassLayout tables. The records of these tables contain the following entries:

  • The TypeDef table contains the Flags, Name, Namespace, Extends, FieldList, and MethodList entries.

  • The TypeRef table contains the ResolutionScope, Name, and Namespace entries.

  • The InterfaceImpl table contains the Class and Interface entries.

  • The NestedClass table contains the NestedClass and EnclosingClass entries.

  • The ClassLayout table contains the PackingSize, ClassSize, and Parent entries.

TypeDef Table Validity Rules

  • The Flags entry can have only those bits set that are defined in the enumeration CorTypeAttr in CorHdr.h (validity mask: 0x00173DBF).

  • [run time] The Flags entry cannot have the sequential and explicit bits set simultaneously.

  • [run time] The Flags entry cannot have the unicode and autochar bits set simultaneously.

  • If the rtspecialname flag is set in the Flags entry, the Name field must be set to _Deleted*, and vice versa.

  • [run time] If the bit 0x00040000 is set in the Flags entry, either a DeclSecurity record or a custom attribute named SuppressUnmanagedCodeSecurityAttribute must be associated with the TypeDef, and vice versa.

  • [run time] If the interface flag is set in the Flags entry, abstract must be also set.

  • [run time] If the interface flag is set in the Flags entry, sealed must not be set.

  • [run time] If the interface flag is set in the Flags entry, the TypeDef must have no instance fields.

  • [run time] If the interface flag is set in the Flags entry, all the TypeDef ’s instance methods must be abstract.

  • [run time] The visibility flag of a nonnested TypeDef must be set to private or public.

  • [run time] If the visibility flag of a TypeDef is set to nested public, nested private, nested family, nested assembly, nested famorassem, or nested famandassem, the TypeDef must be referenced in the NestedClass entry of one of the records in the NestedClass metadata table, and vice versa.

  • The Name field must reference a nonempty string in the #Strings stream.

  • The combined length of the strings referenced by the Name and Namespace entries must not exceed 1023 bytes.

  • The TypeDef table must contain no duplicate records with the same full name (the namespace plus the name) unless the TypeDef is nested or deleted.

  • [run time] The Extends entry must be nil for TypeDefs with the interface flag set and for the TypeDef System.Object of the Mscorlib assembly.

  • [run time] The Extends entry of all other TypeDefs must hold a valid reference to the TypeDef or TypeRef table, and this reference must point at a nonsealed class (not an interface or a value type).

  • [run time] The Extends entry must not point to the type itself or to any of the type descendants (inheritance loop).

  • [run time] The FieldList entry can be nil or hold a valid reference to the Field table.

  • [run time] The MethodList entry can be nil or hold a valid reference to the Method table.

Enumerator-Specific Validity Rules

If the TypeDef is an enumerator—that is, if the Extends entry holds the reference to the class [mscorlib]System.Enum—the following additional rules apply:

  • [run time] The interface, abstract, sequential, and explicit flags must not be set in the Flags entry.

  • The sealed flag must be set in the Flags entry.

  • The TypeDef must have no methods, events, or properties.

  • The TypeDef must implement no interfaces—that is, it must not be referenced in the Class entry of any record in the InterfaceImpl table.

  • [run time] The TypeDef must have at least one instance field of integer type, or of type bool or string.

  • [run time] All static fields of the TypeDef must be literal.

  • The type of the static fields of the TypeDef must be the current TypeDef itself.

TypeRef Table Validity Rules

  • [run time] The ResolutionScope entry must hold either 0 or a valid reference to the AssemblyRef, ModuleRef, Module, or TypeRef table. In the last case, TypeRef refers to a type nested in another type (a nested TypeRef).

  • If the ResolutionScope entry is nil, the ExportedType table of the prime module of the assembly must contain a record whose TypeName and TypeNamespace entries match the Name and Namespace entries of the TypeRef record, respectively.

  • [run time] The Name entry must reference a nonempty string in the #Strings stream.

  • [run time] The combined length of the strings referenced by the Name and Namespace entries must not exceed 1023 bytes.

  • The table must contain no duplicate records with the same full name (the namespace plus the name) and ResolutionScope value.

InterfaceImpl Table Validity Rules

A Class entry set to nil means a deleted InterfaceImpl record. If the Class entry is non-nil, however, the following rules apply:

  • [run time] The Class entry must hold a valid reference to the TypeDef table.

  • [run time] The Interface entry must hold a valid reference to the TypeDef or TypeRef table.

  • If the Interface field references the TypeDef table, the corresponding TypeDef record must have the interface flag set in the Flags entry.

  • The table must contain no duplicate records with the same Class and Interface entries.

NestedClass Table Validity Rules

  • The NestedClass entry must hold a valid reference to the TypeDef table.

  • [run time] The EnclosingClass entry must hold a valid reference to the TypeDef table, one that differs from the reference held by the NestedClass entry.

  • The table must contain no duplicate records with the same NestedClass entries.

  • The table must contain no records with the same EnclosingClass entries and NestedClass entries referencing TypeDef records with matching names—in other words, a nested class must have a unique name within its encloser.

  • The table must contain no sets of records forming a circular nesting pattern—for example, A nested in B, B nested in C, C nested in A.

ClassLayout Table Validity Rules

A Parent entry set to nil means a deleted ClassLayout record. However, if the Parent entry is non-nil, the following rules apply:

  • The Parent entry must hold a valid reference to the TypeDef table, and the referenced TypeDef record must have the Flags bit explicit or sequential set and must have the interface bit not set.

  • [run time] The PackingSize entry must be set to 0 or to a power of 2 in the range 1 to 128.

  • The table must contain no duplicate records with the same Parent entries.



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net