Resolution: Exception while accessing “SPWebService.ContentService” object

Recently I came across a situation in which a customer was trying to access the web applications in the farm but he was getting an exception, “System.NullReferenceException was unhandled  Message=Object reference not set an instance of an object.” while executing “SPWebService.ContentService” from a console application as below.


Initially we started looking into what is wrong with the user permissions but logged in user had all the required rights(Farm Admin) but, after digging further we found that it’s a Visual Studio 2010 issue, the project was marked as x86 which definitely SP2010 doesn’t like:) Made the project build type as x64(Right click on the project in Solution Explorer –> Project Properties –> Build –> Platform target –> x64) and everything started working fine.

I initially searched for the exceptions around this API and couldn’t find any hints so thought of posting the quick hint here. Hope it helps!

Comments (5)

  1. Vincent says:

    What if…

    …the user is a farm admin

    …the build settings are x64

    …and SPWebService.ContentService still retuns null?

  2. -Tejas says:


    did you try accessing the ContentService object on the SharePoint machine iteself than any other machine?

    Also, we can check using fiddler tool whether any problem accessing the web service, you can start the fiddler tool and access the web service from the same machine's browser where you are running your code. this should tell us what response we get from server.

  3. Vincent says:

    I am testing my project on 2007 and just tested it for the first time on 2010. Everything worked except this, and it is because I target the .net 4 framework…/f8a19b11-11b3-4878-9980-134ac535de04

  4. Naresh says:

    Thank you for posting valuable things. it'e helped me alot.

  5. Mahesh says:

    Thanks for this post. i was getting the same problem and it immediately helped me… thanks a lot…..

Skip to main content