Creating List Instance: Object Reference not set to an instance of an object
Introduction
This one is a bit of an old issue but some of my posts are just to remind me of a time that I got stuck in the past. Also if it helps someone else then great.
It is possible to create a feature which creates an instance of a SharePoint List when its activated. However, sometimes you only want a list to be created on the Root Web of a site collection.
Issue
Well the XML for specifying a ListInstance as a feature has an attribute called RootWebOnly which I thought I could use to only allow the ListInstance to be created on the RootWeb.
Unfortunately when you do that you get a message like the following in your SharePoint ULS Logs when the feature is activated:-
Feature Activation: Threw an exception, attempting to roll back. Feature ‘FeatureName’(ID: ‘xxxxxxxx-xxxx-xxxx-xxxxxxxx). Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.SPListInstanceElement.ElementActivated(SPFeaturePropertyCollection props, SPSqlCommand sqlcmdAppendOnly, SPWebApplication webApp, SPSite site, SPWeb web, Boolean fForce)
at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionListInstances(SPFeaturePropertyCollection props, SPSite site, SPWeb web, Boolean fForce)
at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce)
at Microsoft.SharePoint.SPFeature.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce)
at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce)
The offending Feature ListInstance element is below:-
1: <?xmlversion="1.0" encoding="utf-8"?>
2: <Elements
3: xmlns="http://schemas.microsoft.com/sharepoint/">
4: <ListInstance
5: Id="AListId"
6: Title="A List"
7: Description="A List
8: Description”
9: Url="Lists/ListUrlHere"
10: OnQuickLaunch="FALSE"
11: RootWebOnly=”TRUE”
12: FeatureId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"
13: TemplateType="45100"></ListInstance>
14: </Elements>
Solution
To fix the feature activation remove the RootWebOnly=”TRUE” from your ListInstance element manifest file and instead move the RootWebOnly=”TRUE” into your List’s schema.xml.
To ensure that the list is only provisioned at the root web of the site collection change the Feature.xml to use Scope=”Site”
Update:
Thanks to Dennis who picked up my mistake in this post which stated that the RootWebOnly attribute should be moved to the feature.xml.
Thoughts? Comments about this post? Please leave them here.. Cancel reply
Search
Twitter Feed
- RT @cimares: Don't forget this weeks #suguk London on Thurs 23rd at Microsoft Victoria. 6pm suguk.org/Event.aspx?id=… #sharepint after. #share…- 22 hours ago
- XBox One TV capabilities looks interesting though how will that work with Satellite / Cable boxes by Sky / Virgin?- 23 hours ago
- The Xbox One capabilities look good, impressed by the comparison between COD MW3 and Ghosts bit.ly/167d10r- 23 hours ago
- RT @tristanwatkins: New post: RMS AD Caching for #SP2010 Users tristanwatkins.com/rms-ad-caching… - part six in my #SharePoint with #RMS series #IRM- 1 day ago
- RT @mattmoo2: Off to the airport heading to Edinburgh for the first Office 365 UK User Group in Scotland so excited #o365uk- 1 day ago
Recent Posts
Most Active Posts
- Open PDF files from a Document Library in a New Window
- Issue with Updating SharePoint Publishing Page Layouts and Ghosting
- How we deployed SharePoint WSP Solutions without downtime
- My experiences when migrating from iPhone 5 to Nokia Lumia 920 (Windows 8 Phone)
- Corrupted List Url Fix: Link to SharePoint List points to /_layouts/listedit.aspx?List=[ListGuid]
Recommended Resources
- Andrew Connell’s Blog
- Chris O’Brien’s Blog
- Dave Coleman’s Blog
- Eric Shupp’s Blog
- Glyn Clough’s Blog
- Jaap Vosser’s Blog
- Martin Hatch’s Blog
- Paul Culmsee’s Blog
- Seb Matthew’s Blog
- Stephen Cummins Blog
- Stuart Starrs Blog
- The MOSS Show (Podcast)
- The SharePoint Podshow
- UK SharePoint User Group
- Wes Hackett’s Blog
Archive
- April 2013 (1)
- March 2013 (1)
- February 2013 (1)
- July 2012 (4)
- June 2012 (3)
- January 2012 (1)
- December 2011 (1)
- November 2011 (1)
- October 2011 (2)
- September 2011 (1)
- August 2011 (1)
- July 2011 (1)
- June 2011 (2)
- May 2011 (3)
- April 2011 (3)
- March 2011 (1)
- February 2011 (4)
- November 2010 (2)
- July 2010 (2)
- June 2010 (1)
- May 2010 (2)
- April 2010 (1)
- March 2010 (1)
- February 2010 (1)
- January 2010 (2)
- December 2009 (1)
- November 2009 (5)
- October 2009 (4)
- August 2009 (1)
- July 2009 (2)
- March 2009 (1)
- February 2009 (2)
- December 2008 (3)
- November 2008 (1)
- October 2008 (8)
- July 2008 (2)
- June 2008 (3)
- May 2008 (3)
- April 2008 (3)
- November 2007 (4)
- August 2007 (4)
- April 2007 (2)
Stats
- 41,695 hits
“instead move the RootWebOnly=”TRUE” into your Feature’s feature.xml”
As far as I can tell there is no RootWebOnly attribute in the feature.xml?!
Hi Dennis,
Thank you for your comment and taking the time to respond. You are right there is no RootWebOnly attribute for a Feature element.
Which makes sense because if you only want to make the feature available at a root web site then you would scope the feature by setting the Scope=”Site”.
I looked at my List definition and I had moved the RootWebOnly=”true” property into the List’s Schema.xml element.
I will update the post.
Thanks
Simon
Genius! I was getting exactly this problem and this resolved it for me. Would never have thought to move that property to schema and was just considering abandoning list creation in CAML and write code instead. Many thanks!
BTW, thanks MS for really helpful error, once again..
Steve,
Thanks very much for taking the time to comment, glad that it helped, I remember going through the same frustrations.
Cheers
Simon