donderdag, mei 02, 2013

SharePoint Client-Side Object Model ClientContext.Load method

Today I was struggling with my first try at some SharePoint 2013 Client Side Object Model C# code, starting with the example I found at

As all of you may know, you need to reference at least two assemblies to get this going:
  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll
Unfortunately at that point I was still inexperienced, and I forgot to add a reference to Microsoft.SharePoint.Client.Runtime.dll.

When I tried to compile the following code:
The compiler threw the following error message:

  • 'Microsoft.SharePoint.Client.ClientContext' does not contain a definition for 'Load' and no extension method 'Load' accepting a first argument of type 'Microsoft.SharePoint.Client.ClientContext' could be found (are you missing a using directive or an assembly reference?
Luckily the compiler hinted to the possible fact that there was missing a assembly reference.

Finally, I added Microsoft.SharePoint.Client.Runtime.dll as well and the errors went away.

I found it quite confusing that I was able to use a class but not all available methods, assuming the example I took was right of course.

So I digged into the decompilation of both assemblies and this is what I found out:
  • ClientContext inherits from ClientRuntimeContext
  • ClientContext is defined in Microsoft.SharePoint.Client.dll
  • ClientRuntimeContext is defined in Microsoft.SharePoint.Client.Runtime.dll
  • ClientRuntimeContext defines the Load method:
Hopefully this piece of information is useful to some of you out there.

Geen opmerkingen: