September 28, 2011

Console application with SharePoint client object model crashes when run remotely

So I started experimenting with the new client object model that comes with SharePoint 2010. I created a console application that references Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll to use the capabilities of this object model.
I created an application that simply looks at one of the lists on my root site and prints out the list name, COOL app huh!
using System;
using System.Net;
using Microsoft.SharePoint.Client;
 
namespace SharePointTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var credential = new NetworkCredential("user", "pass", "domain");
                var clientContext = new ClientContext("http://sp2010") {Credentials = credential};
                Web web = clientContext.Web;
 
                List projects = web.Lists.GetByTitle("Projects");
                clientContext.Load(projects);
                clientContext.ExecuteQuery();
                Console.WriteLine("List name: {0}.", projects.Title);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
    }
}
Worked like a charm on my virtual development box that has SP2010 installed on it. So I decided to move it to my Win7 environment to see if it does what it claims to do (which is run remotely!). To come to a surprise that application crashes! even when wrapping my code with Try Catch blocks.

Issue

Console application with SharePoint client object model crashes when run remotely.

Solution

Register Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll in GAC on the remote computer where you like to run your application that references the above assemblies.

No comments:

Post a Comment