NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
How Long For Me
SaveMySerials

Blog
Twitter

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.

Tags

SharePoint

Related Blogs

SharePoint Browser 1 Released!
Using Ext JS in SharePoint... a tip
Starting SharePoint workflow for each item in a list
Automatically Setting File Name in SharePoint when submitting an InfoPath 2007 Form
Fixing MOSS Search Crawler issue for "The specified address was excluded..."

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


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