Skip to content

Folder Update Errors - UniqueContentTypeOrder/Properties #4438

@percheron1

Description

@percheron1

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Expected or Desired Behavior

We've had functional and unchanged CSOM operating against SharePoint Online for months without issue. Sometime between 5 August at noon Eastern (last successful execution) and 6 August at noon Eastern an 'Object reference not set to an instance of an object'
exception began surfacing in two areas [I suspect they're related since they happened concurrently, so for now I'm doing one bug submission. If you'd rather they be separated, that can be accomplished @VesaJuvonen ]. The first area is in setting a folder's UniqueContentTypeOrder and the second is setting a value for a folder's property bag. I suspect both are related since I can see the values for UniqueContentTypeOrder being persisted to the folder's property bag.

Obviously, I'm guessing here, but if Property persistence is an issue and UniqueContentTypeOrder on the back end relies on Property persistence, then I guess it would make sense to have a null object reference exception as it's storage does not return anything.

Microsoft.SharePointOnline.CSOM version 16.1.9021.1200 is being used.

The desired outcome is persisting Folder UniqueContentTypeOrder and Property values.

Observed Behavior

For UniqueContentTypeOrder, upon calling ClientContext ExecuteQuery, a server exception is generated:

Microsoft.SharePoint.Client.ServerException
  HResult=0x80131500
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.SharePoint.Client.Runtime
  StackTrace:
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

When setting a folder property bag entry, execution completes, but the value is not persisted to the property bag.

Steps to Reproduce

Create a few site content types deriving from Site Page and associate them with the Site Pages library. Configure the Site Pages library to use content types.

// Example for UniqueContentTypeOrder

using (ClientContext ctx = new ClientContext("<some SharePoint Online site collection>"))
{
    ctx.Credentials = new SharePointOnlineCredentials( ... , ... );
    Site site = ctx.Site;
    Web root = ctx.Site.RootWeb;
    ctx.Load(site);
    ctx.Load(root, r => r.AvailableContentTypes, r => r.ServerRelativeUrl);
    ctx.ExecuteQuery();

    List sitePages = root.GetList(root.ServerRelativeUrl + "/sitepages");
    ctx.Load(sitePages.ContentTypes);
    IList<ContentTypeId> order = new List<ContentTypeId>();

    // List ContentTypeIds are referenced for simplicity
    foreach (string ct in new string[] {
        "<sample list content type id 1>", // This is the content type id for the list's first sample content type
        "<sample list content type id 2>", // This is the content type id for the list's second sample content type
        "<sample list content type id 2>"  // This is the content type id for the list's third sample content type
    })
    {
        ContentType found = sitePages.ContentTypes.GetById(ct);
        ctx.Load(found);
        ctx.ExecuteQuery();
        order.Add(found.Id);
    }

    Folder sitePagesRoot = sitePages.RootFolder;
    ctx.Load(sitePagesRoot);
    ctx.Load(sitePagesRoot, r => r.UniqueContentTypeOrder); // Same result whether the UniqueContentTypeOrder is retrieved or not - regardless, it's always null as it has never been assigned before.
    ctx.ExecuteQuery();

    sitePagesRoot.UniqueContentTypeOrder = order;

    sitePagesRoot.Update();
    ctx.ExecuteQuery(); // Get an "Object reference not set to an instance of an object." exception.  Even occurs with an empty IList<ContentTypeId> object.

}

// Example for a folder Properties not being persisted

using (ClientContext ctx = new ClientContext("<some SharePoint Online site collection>"))
{
    ctx.Credentials = new SharePointOnlineCredentials( ... , ... );
    Site site = ctx.Site;
    Web root = ctx.Site.RootWeb;
    ctx.Load(site);
    ctx.Load(root, r => r.ServerRelativeUrl);
    ctx.ExecuteQuery();

    List sitePages = root.GetList(root.ServerRelativeUrl + "/sitepages");
    Folder sitePagesRoot = sitePages.RootFolder;
    ctx.Load(sitePagesRoot.Properties);
    ctx.ExecuteQuery();

    sitePagesRoot.Properties.FieldValues.Add("hello", "world"); // Original code, execution completes, not persisted in property bag
    sitePagesRoot.Properties.FieldValues["hello2"] = "world2"; // execution completes, not persisted in property bag
    //sitePagesRoot.Properties["Hello3"] = "world3";  // For completeness, chucks an "Object reference not set to an instance of an object."  exception

    sitePagesRoot.Update();
    ctx.ExecuteQuery();

}

Thoughts?

Steve

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APIlistmaintenance-oldissuesMarked for outdated issues as part of cleaning processstatus:to-be-reviewedIssue needs to be reviewed by Microsoft for additional follow up / review.type:bug-suspectedSuspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions