Microsoft Premier Field Engineer - SharePoint

All posts are provided "AS IS" with no warranties, and confers no rights.

Resolution: Exception while accessing “SPWebService.ContentService” object

Resolution: Exception while accessing “SPWebService.ContentService” object

  • Comments 5

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.

image

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
  • What if...

    ...the user is a farm admin

    ...the build settings are x64

    ...and SPWebService.ContentService still retuns null?

  • Vincent,

    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.

  • 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

    social.msdn.microsoft.com/.../f8a19b11-11b3-4878-9980-134ac535de04

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

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

Page 1 of 1 (5 items)
Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post