Thursday, September 26, 2019

Tip: SharePoint 365 CSOM Nuget Package

Which on to use for SharePoint Online, when you want to use CSOM to connect to it?

NOT To Use


To Use

The reason for this post is to let people know that whenever you someone try to execute some operations to SharePoint Online and receive the following error, when your codes seem to be correct:
Microsoft.SharePoint.Client.CollectionNotInitializedException HResult=0x80131509 Message=The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. Source=Microsoft.SharePoint.Client.Runtime
The are two reasons for such scenario:

  1. Try to access some properties within the CSOM object namespace but did not execute the proper "Load" and "ExecuteQuery" functions. 
  2. Used the wrong library version. As indicated above the package shown in first picture is for SharePoint2010 whereas the second picture is for SharePoint Online.

No comments: