Question

I'm attempting to create a web part page from scratch, but I keep running into the following error, which occurs post-Init:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.SharePoint.WebPartPages.WebPartResultSet.get_PartOrder() +77
   Microsoft.SharePoint.WebPartPages.SPWebPartManager.CreateWebPartsFromRowSetData(Boolean onlyInitializeClosedWebParts) +6693
   Microsoft.SharePoint.WebPartPages.SPWebPartManager.LoadWebParts() +146
   Microsoft.SharePoint.WebPartPages.SPWebPartManager.OnPageInitComplete(Object sender, EventArgs e) +288
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnInitComplete(EventArgs e) +11056990
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1674

I have tried:

  • Using default.master
  • Not using default.master (adding an SPWebPartManager to the page)
  • Creating the page as a module of a web part
  • Creating the page in the _layouts folder
  • Creating the page as a component of a list definition
  • Zones: Single, Multiple, None
  • Web Parts: Single, Multiple, None, Inside Zones, outside Zones
  • Opening an UI-created Web Part Page in Designer, copying out the contents, and pasting them into a file
  • Inheriting from Microsoft.SharePoint.WebPartPages.WebPartPage
  • Inheriting from a code-behind class that inherits from Microsoft.SharePoint.WebPartPages.WebPartPage
  • With and without code behind
  • Googling the error's source function (nothing)
  • Examining the function with Reflector (apparently the WebPartResultSet is null, but I can't find why)

The Madness is calling (baa). Please help.

Was it helpful?

Solution

So, it seems the Module is necessary and has to be correctly configured. Most of my problem above was not knowing about having a Module, and the rest by not having it set up properly.

Here are some useful links on the matter; a mashup of which I used the create the eventual solution:

OTHER TIPS

A bit late and on Sharepoint 2010, but: I fixed similar error when deploying a list definition feature without any pages or webparts, but with list views associated with such, by adding simple "WebPartZoneID="Main"" to a view def.

<View DefaultView="TRUE"
        BaseViewID="98"
        MobileView="TRUE" 
        WebPartZoneID="Main"
        Type="HTML" 
        DisplayName="Last modified" 
        Url="Forms/LastModified.aspx" 
        SetupPath="pages\viewpage.aspx" 
        ImageUrl="/_layouts/images/dlicon.png">

Important parts are SetupPath, WebPartZoneID and BaseViewID. This code (and the view definition below it, of course) creates a kind of "default" list view page, that could be referenced then by shown URL. The page contains only the specified list in specified view. Seems way better than deploying a web part page via module.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top