Question

I'm attempting my first foray into the Client Object Model.

In the following code,

   using (ClientContext context = new ClientContext(url)) // url works w- SPSite
   {
      Web web = context.Web;
      context.Load(web);

      Log.Debug("Loading web.");
      context.ExecuteQuery();
   }

The call to ExecuteQuery throws an exception:

Unhandled Exception: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

With so little info, I'm a little lost on where to begin debugging. There is no traffic in the ULS relating to an event... just this simple exception. What can I look into?

Was it helpful?

Solution

An important note that I didn't realize was relevant in my question: my code is in a console application.

It was necessary for me to provide credentials to the ClientContext like so:

using (ClientContext context = new ClientContext(url)) // url works w- SPSite
   {
      // the domain parameter is optional
      // there is a constructor that takes only a username and password
      context.Credentials = new NetworkCredential("username", "password", "domain"); 

      Web web = context.Web;
      context.Load(web);

      Log.Debug("Loading web.");
      context.ExecuteQuery();
   }

This resolved my HTTP 500. However, I now have to figure out why I'm seeing an HTTP 401.

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