I'm trying to connect to a SharePoint 2010 site using the .NET Client Object Model. When I run test code from a windows console app that I have written, I have no problems. When I try to run the same code through the process it will be used in (a scheduled task) I receive the above error.
I have used the following code the connect to the site in both cases:-
using (SP.ClientContext oContext = new SP.ClientContext(SharePointUrl))
{
oContext.Credentials = new NetworkCredential("user", "password", "domain");
SP.Web oWeb = oContext.Web;
oContext.Load(oWeb);
SP.List caseList = oWeb.Lists.GetByTitle("MyList");
oContext.Load(caseList);
oContext.ExecuteQuery();
}
When I ran the code from the scheduled task without the credential info, I received an Unauthorised error (which I would expect) but am at a loss as to why the code is failing now I have provided the credentials. When I run the console app with the credential info, I can access the site data.
Does anybody have any ideas? Thanks.
EDIT By changing the URL of the SharePoint site to be one not installed locally on my development machine I have lost the error message above and I now get the error "The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.". Again, testing on my console app works fine.