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.

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!