<< Back To All Blogs
Receiving null value when using SPFarm.Local on SharePoint 2010
Wednesday, August 8th, 2012
We recently encountered an issue where we were running an application to export granular permissions using the SharePoint 2007 object model before migrating to SharePoint 2010. In order to verify we planned to run the application on SharePoint 2007 before migration, and later run the same program on SharePoint 2010 to run a WinDiff and make comparisons afterwards.
The program is fairly basic and loops through the web apps and webs underneath each web app. The start of the program opens with:
SPFarm farm = SPFarm.Local;
When we ran this same program on SharePoint 2010 we encountered a NullReferenceException (farm was null).
After some debugging and digging we encountered two causes for this issue:
1. The user executing the application does not have the same permissions level as the SPS Farm account (which most farm admins should have)
2. The application was compiled for an x86 architecture but should be compiled against x64. The odd thing with this is that it doesn't actually throw an architecture exception or an invalid image message, it simply doesn't work. Reset your Visual Studio application to add an x64 configuration with x64 as the target architecture in your build configuration, and you're good to go!
Architecturin' Tom Out.
What causes "Please wait while scripts are loaded..." in SharePoint
Understanding SharePoint Template Ids
Fixing "Error in loading DLL" in SharePoint
Configuring Nintex Request Approval Action Permissions in SharePoint
Currently no comments.
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: