This project is read-only.

PeWriter fails to find fields

Topics: PE Writer
Aug 2, 2010 at 10:07 PM

GetFieldDefIndex fails on fields (generated by F#).

When I run through WritePeToStream, PeWriter tries to get the field definition index of an IFieldDefinition object, which fails because two different implementations of IFieldDefinition (mutable and immutable) object hash to different values.

For grins, I made an IEqualityComparer<IFieldDefinition> like so:

  internal class FieldDefinitionComparer : IEqualityComparer<IFieldDefinition>
      MemberRefComparer comparer;
      internal FieldDefinitionComparer(PeWriter writer)
          comparer = new MemberRefComparer(writer);

      public bool Equals(IFieldDefinition x, IFieldDefinition y)
          return comparer.Equals(x, y);

      public int GetHashCode(IFieldDefinition field)
          return comparer.GetHashCode(field);

And changed the construction of fieldDefIndex to use it as the Comparer for the Dictionary - the initial case succeeded, but then failed on a later case.

At this point, I'm over my budget of time to try to fix this problem.

in GetFieldDefIndex, I'm seeing this field passed in:

+        field    {Atalasoft.Imaging.OctTree.Leaf.item}    Microsoft.Cci.IFieldDefinition {Microsoft.Cci.MetadataReader.ObjectModelImplementation.FieldDefinition}

and in the hashtable, I see this item:

+        [21]    {[Atalasoft.Imaging.OctTree.Leaf.item, 22]}    System.Collections.Generic.KeyValuePair<Microsoft.Cci.IFieldDefinition,uint>

-        Key    {Atalasoft.Imaging.OctTree.Leaf.item}    Microsoft.Cci.IFieldDefinition {Microsoft.Cci.MutableCodeModel.FieldDefinition}

which presumably represents the same item, one mutable one not.