wjhguitarman
wjhguitarman

Reputation: 1073

Get the Default Service Account in SharePoint 2010 via C#

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

Answers (1)

wjhguitarman
wjhguitarman

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

Related Questions