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

  • I just noticed that my sitecollections could be in different content databases. that might change the story over here – Luis Valencia 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. – Luis Valencia Apr 2 '12 at 21:05

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

  • 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. – Luis Valencia 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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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