Mailing List



NerdyHearn - Blog

<< 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.



Related Blogs

Creating a dynamic SharePoint settings DropDown using a ToolPart
Retrieving data from SharePoint SOAP Requests using LINQ

SharePoint Error Craziness: Volume 2
SharePoint STSADM AddSolution Object Reference not set to an Instance of the Object error


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:

NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers