May 25 / Michiel

FieldRefs not working with XML comments

Today I was working on a SharePoint 2010 project where the custom fields and content types where provisioned using a feature. After the feature was activated the custom fields and content types where provisioned in SharePoint, except the content type contained no fields. The element manifest file contained the following xml:

  <!-- Base Page -->
<ContentType ID="0x010100C568DB52D9D0A1...84E219954237AF3901"
              Name="Basepage"
              Description="Basepage"
              Group="Publishing"
              Sealed="TRUE"
              Inherits="TRUE"
              Version="1">
  <FieldRefs>
    <!-- Originating from MOSS -->
    <FieldRef ID="{b66e9b50-a28e-469b-b1a0-af0e45486874}"
            Name="Keywords" />
    <!-- Custom fields -->
    <FieldRef ID="{30607e4e-a3e1-4662-9766-56e1faedb875}"
            Name="AdminComments" />
  </FieldRefs>
</ContentType>

The ULS logs showed no errors and I couldn’t figure out what the problem was because the same element manifest file was used in SharePoint 2007. After the stripping the file I figured out that the xml comments were causing the problem. Now my element manifest contains the following:

<ContentType ID="0x010100C568DB52D9D0A1...84E219954237AF3901"
              Name="Basepage"
              Description="Basepage"
              Group="Publishing"
              Sealed="TRUE"
              Inherits="TRUE"
              Version="1">
  <FieldRefs>
    <FieldRef ID="{b66e9b50-a28e-469b-b1a0-af0e45486874}"
            Name="Keywords" />
    <FieldRef ID="{30607e4e-a3e1-4662-9766-56e1faedb875}"
            Name="AdminComments" />
  </FieldRefs>
</ContentType>

The content is the same except the comments are missing.

4 Comments

leave a comment
  1. Serge van den Oever / Sep 26 2010

    Just ran into the same issue… costed me a few hours, this is so annoying… Thanks for writing this down. Now I know its not me…

  2. Olaf / Oct 14 2010

    We just had the opposite. Deploying our solution would produce an error on the very first of the FieldRef elements, unless we added an empty comment just before it.

    Very weird!

  3. Chris OConnor / Apr 8 2011

    Yep – had me stumped for a few hours – annoying ! Took out the comments – and then it worked. FFS !

    Thanks – btw !

  4. Adrian / Jul 31 2011

    Thank you so so much for posting this. This one has kept us going many days and caused all sorts of problems with missed deadlines.

Leave a Comment

*