Simon Sebright

Simon Sebright
10.10.2012
0 Kommentar(e)

An xml comment in your content type fieldref list will cause you problems after deployment.  In my case, there were missing fields, and no errors or warnings anywhere to be seen.

Xml blues in the SharePoint Content Type parser

 
The other day I spent some time scratching my head and tearing my hair out.  A project which has been working fine until then suddenly went belly-up.  All I did was add a new FieldRef of an existing field element to an existing content type.  Suddenly things stopped working.  On creating a site collection using this content type, I started to get error messages that my fields didn't exist.  There was no error that the content type was invalid.  Strange.
 
It took me longer than usual to get to the bottom of it because the error occurred in Site Collection creation where a feature was automatically activated, meaning debugging and the deploy/iisreset cycle were tiresome.  Because the site creation failed, I had nothing to look at.
 
I even went through all the open changes against my checkout out version from source control - I couldn't see anything odd.  Sure I had changes, but that's what you do when you develop!
 

Breakthrough

 
The breakthrough came when I commented out the event receiver using the fields (and another iisreset, deploy, etc., etc.).  The error did not occur, meaning I could examine my list and content type.  Lo and behold it was there, containing only the new field I had added.  I had added the new field first, so the rest were missing.  Why?

Well, I found out it's because I had an xml comment in the content type definition, to remind me why the field was there.  That caused the content type processing to stop at that point.  Somewhat annoyingly this did not cause an error of any kind - a dangerous situation.

Well, only the good folks at Microsoft can tell us why for sure, but it looks like there xml treatment of the Elements.xml file is less than ideal.

In short, don't do this:

<ContentType ID="0x010100..."

                 Name="MyContentType"

                 Group="Project 1"

                 Description="Groovy"

                 Inherits="TRUE"

                 Version="0">

        <FieldRefs>

            <FieldRef ID="{99F38C7E-0493-4beb-B1AE-2E2396B78BA2}" Name="NiceNewField"/> <!-- Needed to make the XXZ Widget work and this comment will break the content type! -->

            <FieldRef ID="{F55C4D88-1F2E-4ad9-AAA8-819AF4EE7EE8}" Name="PublishingPageContent" />

            <FieldRef ID="{D6E31868-E402-4c28-BCDD-F8C517A7897B}" Name="CommentingEnabled" />

            <FieldRef ID="{1B14D023-939E-497e-9621-21CA3FDE7DDD}" Name="RatingEnabled" />

            <FieldRef ID="{EBDF37A6-5DA2-48a2-9493-FCFEDD40598E}" Name="TaggingEnabled" />

            <FieldRef ID="{D33453AC-5B1B-4A04-9673-CFBA8368195D}" Name="Keywords"/>

            <FieldRef ID="{A45C395D-BBBF-47D8-9A46-3A3E070EB535}" Name="KeywordsTaxHTField0" Hidden="TRUE"/>

        </FieldRefs>
                  ...

Tags

Kommentar hinterlassen




Retype the numbers below:
 Security code
----

Kommentar(e)

Noch keine Kommentare.