0

I recently deployed a visual web part I created to my SharePoint 2013 dev environment. The visual web part included a list definition. Around that time I noticed that whenever I go to the list settings page for any list, I get the following error:

Server Error in '/' Application.

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

Source Error: 

Line 14:         }
Line 15:         //spList = SPControl.GetContextWeb(Context).Lists.GetList(new Guid(strLists[0]), true);
Line 16:         if (SPBaseType.Survey == spList.BaseType)
Line 17:         {
Line 18:             string redirectUrl = "survedit.aspx?List=" + strLists[0];

Source File:  c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\listedit.aspx    Line:  16 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   ASP._layouts_15_listedit_aspx.OnLoad(EventArgs e) in c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\listedit.aspx:16
   System.Web.UI.Control.LoadRecursive() +67
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3810

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2053.0 

I don't know if this is due to the list definition I deployed with the web part. Any help is appreciated.

Edit: I should clarify the code above is not mine, it is in SharePoint. The web part I created is mostly client-side, using restAPI to access list data. The only server-side code in the web part creates hidden fields for the web part properties so they can be accessed my javascript function. I am thinking that when I deployed the project, I somehow broke the SharePoint list settings page.

Edit: Below is my list definition in my visual web part project

Elements.xml file:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List project item, an error will occur when the project is run. -->
    <ListTemplate
        Name="MJBSynopsisList"
        Type="100"
        BaseType="0"
        OnQuickLaunch="TRUE"
        SecurityBits="11"
        Sequence="410"
        DisplayName="MJBSynopsisList"
        Description="My List Definition"
        Image="/_layouts/15/images/itgen.png"/>
</Elements>

Schema.xml file:

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="MJBSynopsisList" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/MJBSynopsisList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentType ID="0x010019e39774dd04447986f2a0289547604f" Name="ListFieldsContentType">
        <FieldRefs>
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
          <FieldRef ID="{7b29fd85-810b-4a1c-afda-c8e43042fb53}" Name="SynopsisUrl" />
          <FieldRef ID="{0f71dc7b-0642-427c-8dc2-462fa0fd706f}" Name="SynopsisDetails" />
          <FieldRef ID="{8ecb2fe3-0ac2-4b7c-90e0-0e610dc07394}" Name="ItemOrder" />
          <FieldRef ID="{72c75154-7ef3-4216-bc61-81ad8488c039}" Name="ItemActive" />
        </FieldRefs>
      </ContentType>
      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
    </ContentTypes>
    <Fields>
      <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="$Resources:core,Title;" Required="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" MaxLength="255" />
      <Field Name="SynopsisUrl" ID="{7b29fd85-810b-4a1c-afda-c8e43042fb53}" DisplayName="Synopsis Url" Type="URL" />
      <Field Name="SynopsisDetails" ID="{0f71dc7b-0642-427c-8dc2-462fa0fd706f}" DisplayName="Synopsis Details" Type="Note" RichText="TRUE" RichTextMode="FullHtml" Required="TRUE" />
      <Field Name="ItemOrder" ID="{8ecb2fe3-0ac2-4b7c-90e0-0e610dc07394}" DisplayName="Item Order" Type="Number" />
      <Field Name="ItemActive" ID="{72c75154-7ef3-4216-bc61-81ad8488c039}" DisplayName="Item Active" Type="Boolean" Required="TRUE">
        <Default>1</Default>
      </Field>
    </Fields>
    <Views>

      <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="LinkTitleNoMenu"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
        </ParameterBindings>
      </View>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/15/images/generic.png?rev=23" Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <JSLink>clienttemplates.js</JSLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="ID" />
          <FieldRef Name="LinkTitle"></FieldRef>
          <FieldRef Name="SynopsisUrl" />
          <FieldRef Name="SynopsisDetails" />
          <FieldRef Name="ItemOrder" />
          <FieldRef Name="Modified" />
          <FieldRef Name="Editor" />
          <FieldRef Name="Created" />
          <FieldRef Name="Author" />
          <FieldRef Name="ItemActive" />
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="ID"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
        </ParameterBindings>
      </View>
    </Views>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    </Forms>
  </MetaData>
</List>
2

Object reference not set to an instance of an object means you are using an object that not set before, in this case, it's a Null Object and can't be used to get its value or one of its properties!


Based on your code, the issue at line 16 if (SPBaseType.Survey == spList.BaseType)

So Make sure that spList object is already assigned in your code before getting its BaseType.

  • Thanks. I updated my question. This error is from SharePoint, not any code I wrote. – steveareeno Aug 3 '17 at 15:18
  • what about the deployed visual web part?! please add more details about its code ? – Mohamed El-Qassas MVP Aug 3 '17 at 15:28
  • I added the elements and schema xml file definitions to the post. – steveareeno Aug 3 '17 at 21:35
1

I looked at the error again and just realized line 15 of the code displayed in the error page, which sets the spList variable, is commented out! I found the page in the layouts folder in SharePoint, uncommented the line, and the list settings page came up. I checked our QA web front end and this line was not commented out. Now I just have to figure out what caused this line to be come commented out. I know better than to edit a SP system page and no one else would know how to do it. Strange

  • Hi, glad to find you solved your issue, but could you please inform me what's the difference between your answer and my above answer ?! I told you : Make sure that spList object is already assigned in your code before getting its BaseType. and described what's the error message meaning Do you think the above answer is not a solution or at least helpful one? – Mohamed El-Qassas MVP Aug 7 '17 at 13:18
  • I marked your answer as the answer also. I got it stuck in my head that you were discussing custom code I wrote, not a sharepoint system page (one that I never touched). In hind-sight, yours was pretty much the same answer. – steveareeno Aug 7 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.