CQWP Content Query WebPart not working after migration to 2010 – Object reference not set to an instalnce of an object

 You upgraded your site from SharePoint 2007 to 2010. Your site was utilising publishing features, mainly heaps of content by query webparts with custom xslt styles. Some of them are broken now, not displaying or displaying “WebPart cannot be displayed”

You try to edit page, edit webpart properties in investigation was is going on and you get:

[NullReferenceException: Object reference not set to an instance of an object.]    Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.GetFieldTitle(SPField field) +8    Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.populateFieldsToDisplayControlGroup(Boolean clearInvalidMappings) +1166    Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.populateCBQControls() +101    Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart.OnPreRender(EventArgs e) +120

This post has helped me a lot


Basically, there is a bug in CQWP 2010 (or By design), some webparts will have to be modified to exclude fields that do not exist in selected list. In CQWP 2007 it was possible to specify all fields so webpart was reused across many different list schemas and situations. You basically used CommonViewFields to list all custom fields possible, which saved heaps of time exporting/reimporting webpart for different pages.
SharePoint 2010 with concept of slots do not allow this flexibility. Don’t make me wrong, they are great, because you now don’t need CommonViewFields at all. Great, but why didn’t they make it backward compatible???
Fields will have to be revisited for issuing webparts, fields that do not exist in the list will have to be removed from CommonViewFields and from DataMappings
<property name=”CommonViewFields” type=”string”>ArticleStartDate,Date;Comments,Note;Brand,Choice;Category,Choice;sArea,Choice;MyStatus,Choice;Product,Choice;SubjectArea,Text;RenewalEffectiveDate,Date;SalesAndServiceArea,Choice;NewBusinessEffectiveDate,Date;Edition,Text;Ver,Text;File_x0020_Type,Text;FileSizeDisplay,Computed;File_x0020_Size,Lookup;SubCategory,Choice;LastReviewedDate,Date;</property>        <property name=”DataMappings” type=”string”>Title:{fa564e0f-0c70-4ab9-b863-0177e6ddd247},Title,Text;|Description:{9da97a8a-1da5-4a77-98d3-4bc10456e700},_Comments,Note;|LinkUrl:{94f89715-e097-4e8b-ba79-ea02aa8b7adb},FileRef,Lookup;|ImageUrl:{B9E6F3AE-5632-4b13-B636-9D1A2BD67120},EncodedAbsThumbnailUrl,Computed;{543bc2cf-1f30-488e-8f25-6fe3b689d9ac},PublishingRollupImage,Image;|</property>
This can take a while to modify every webpart. Well, no shortcuts here, but this is
the quickest solution:
1. add all  custom document content types to all  libraries that do not have columns stated in commonview fields
2.make them hidden for libraries that shoud not use them
3. At this stage, webpart will not show error but will also not show any items
3. all webparts need to be exported and following properties cleared: Datamappings, datamappingsviewfields, commonviewfields has to be cleared.
4.webpart reimported back to the page, it should still show error, you need to visit edit webpart properties again and click Apply
Now it should be fixed.

One Response to “CQWP Content Query WebPart not working after migration to 2010 – Object reference not set to an instalnce of an object”

  1. Iain Carlin

    That’s brilliant! I’ve been struggling to find out why our daily news web part hasn’t been able to be modified for over 12 months now…this fixed it right away. Thank you very much!


Leave a Reply