0

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?

    1 Answer 1

    0

    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.

    1
    • Maybe also add context.AuthenticationMode = ClientAuthenticationMode.Default; And it's also better if you create a custom class which extends the ClientContext so you can do the authentication in the constructor from your own custom class.CommentedSep 4, 2012 at 8:24

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.