SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to debug a timer job, its WEB application scoped.

When it executes, webapp and sitecollections are null for some reason?

Any idea?

Update1: I changed a little bit the code, check screenshot 2, webAPP is not returning null anymore, but .SITES property is throwing an argument exception, and when I try to get the RootWeb for each site collection I also get the same exception.

I havent been able to iterate on all site collections as I want

enter image description here

enter image description here

share|improve this question
I just noticed that my sitecollections could be in different content databases. that might change the story over here – Esteban V Apr 2 '12 at 9:38
If accessing Sites and RootWeb throws an exception how did you then get to the point where we see the code? Are you sure you're running the updated code (remember to restart the timer service)? – Per Jakobsen Apr 2 '12 at 18:03
Indeed, I asked the same thing in another place, it was really strange, then in the other place they suggested to restart the timer service. and I could past forward. – Esteban V Apr 2 '12 at 21:05
up vote 3 down vote accepted

Timer Jobs run as a background service and thus do not have the context of a Web Application. If you need to access a specific web app in your timer job then you will need to open the site using the usual SPSite site = new SPSite(siteurl) way and then reference the Web Application as site.WebApplication

share|improve this answer
I noticed this, what I did is to add to the property bag of the job definition the urls as List<string> of all site collections I want to process inside the timer job, then in the execute method I deserialize the list and I can create instances of SPSite. It was difficult to notice. but I got it now. – Esteban V Apr 2 '12 at 21:06

Give feature scope to "WebApplication" and activate feature on specific webapplication, which shows reference to webapplication in case of "this.Parent as SPWebApplication"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.