SharePoint Sharpener

Obsessively Sharpening SharePoint

Solution: Accessing SharePoint Site or WebApp via Code Returns Null

with 2 comments


A colleague of mine recently developed a timer job for SharePoint. The job worked fine on his developer and test machines but when he tried to activate it in the pre-production environment things went downhill.

An exception was thrown as soon as the timer job attempted to access the web application to add the timer job, ie. in this line of code:

SPContext.Current.Site.WebApplication.JobDefinitions.Add(timerJob)

The exception thrown was the good old “Object reference not set to an instance of an object” and further investigation showed that SPContext returned Null. Accessing the web application by referencing it directly (eg. SPWebApplication wA = SPWebApplication.Lookup(new Uri(http://site)); ) did not make a difference.

Coincidentally, the following error showed up in the event log: “Error in the site data web service”. This error mostly surfaces when SharePoint search chokes in a 32 bit environment due to large lists or inefficient use of memory capacity (heap fragmentation).

The solution

Restarting the below-mentioned services (net start/stop) fixed the problems for us:

net stop "Office SharePoint Server Search"
net start "Office SharePoint Server Search"
net stop "Windows SharePoint Services Search"
net start "Windows SharePoint Services Search"
net stop "Windows SharePoint Services Administration"
net start "Windows SharePoint Services Administration"
net stop "Windows SharePoint Services Timer"
net start "Windows SharePoint Services Timer"
iisreset /noforce

Source: Technet.

Written by Thomas Sondergaard

April 15, 2010 at 3:16 pm

2 Responses

Subscribe to comments with RSS.

  1. Hi,

    was just wonderinh why your colleague was/is using SPContext.Current.Site.WebApplication.JobDefinitions.Add(timerJob).. Is he adding a timerjob using a sitecollection or something? Or he is doing it in the Central Admin?

    Robin

    April 22, 2010 at 11:21 am

  2. Hi Robin,

    I believe he was making a timer job as a web application feature (for activation in Central Administration).

    Thomas Sondergaard

    April 26, 2010 at 8:12 pm


Leave a comment