Reputation: 1073
I am currently trying to make a test console app that will retrieve the SharePoint Farm account and compare it to the list of local administrator users. However, I am having an issue with actually getting the default service account. Currently what I am working with is:
SPProcessAccount user = SPFarm.Local.DefaultServiceAccount;
But this returns a NullReferenceException: Object reference not set to an instance of an object.
I also tried:
string user = SPFarm.Local.DefaultServiceAccount.LookupName();
And that returns the same exception.
This is probably a stupid mistake on my part, but I have been fighting with this to no avail, can anyone help me out?
Upvotes: 1
Views: 1382
Reputation: 1073
After doing some more poking around and researching, I found out the issue. When running in Debug mode I had "Any CPU" selected instead of x64 bit (Sharepoint 2010 is only compatible with 64-bit machines). I also was using .NET 4.5 framework, which apparently is not currently supported by Microsoft.SharePoint. After switching to 64-bit and .NET 3.5 everything works fine.
Upvotes: 1