MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

SPFarm.Local is null

  Asked By: Ariel    Date: Dec 19    Category: MOSS    Views: 2885

I have an issue. In the Page_Load of an ASP.Net Web Application, I am
calling SPFarm.Local. I have added reference to SharePoint.dll and have
imported the namepsaces like Microsoft.SharePoint and
Microsoft.SharePoint.Administration. Also, I am an administrator in the
machine (Dev server)and I am running this application within the SharePoint
server only and not outside. But SPFarm.Local is returning NULL all the
time. The same line of code works for a Windows application's load event
within the same environment and with the same credentials. I googled it and
found that I had to point the Configuration Manager to x64, as my SharePoint
server is running in x64. I did this, but no effect. Also, right now, it
debugs in Any CPU mode, when I reverted it back to the original setting. In
both ways, it doesn't seem to be working. I tried elevating the permission,
by running this piece of code within SPSecurity.RunWithElevatedPrivileges(),
but no effect. I also tried impersonating the user identity, still no
result. I don't know what to do.



10 Answers Found

Answer #1    Answered By: Jude Alston     Answered On: Dec 19

Any replies for the issue below?

Answer #2    Answered By: Araceli Eaton     Answered On: Dec 19

Are you a Farm Admin??????????????

Answer #3    Answered By: Nisarg Kapadia     Answered On: Dec 19

Have you tried accessing the property later in the life cycle of the page?
For example On_Prerender. It may be a timing issue on when this property
gets populated.

Answer #4    Answered By: Jaferry Khan     Answered On: Dec 19

I am not sure whether I am a Farm Admin, but the same code
worked for a Windows app.

Answer #5    Answered By: Davin Knapp     Answered On: Dec 19

It would seem there is a difference between your Windows app and the web app.
When you impersonate, make sure you run a new using(SPSite site = new

You have to create a NEW reference to SPSite to run under the elevated level of
privileges. I don't have any other clues for you

Answer #6    Answered By: Deidra Best     Answered On: Dec 19

Thanks a lot. But I am trying to get the list of all SharePoint
web applications in a farm into a drop down list of an ASP.Net web

Answer #7    Answered By: Rosalinda Merrill     Answered On: Dec 19

Take a look at the following post. Evidently there are two issues. First,
you need to explicitly set the code to run as X64 and second you need to run
the code as a Farm Administrator.


Answer #8    Answered By: Yogendra Zarapkar     Answered On: Dec 19

I saw this article. I tried with x64 environment
also. It didn't work. The ASP.Net web application is running withing the
SharePoint server only. I don't know how to make it running as a Farm
Administrator. I tried using SPSecurity.RunWithElevatedPrivileges and also
with Impersonation. Nothing worked. But the same line of code (SPFarm.Local
) works for a Windows application running within the server. All other
factors remaining more or less the same, SPFarm.Local fails for ASP.Net Web
Application, whereas it works for Windows application. That's why I am

Answer #9    Answered By: Jerad Mercado     Answered On: Dec 19

Are you running any of this with web services?

Answer #10    Answered By: Riley Scott     Answered On: Dec 19

It's an independent ASP.Net web application with reference added to

Didn't find what you were looking for? Find more on SPFarm.Local is null Or get search suggestion and latest updates.