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 thought I could reference SPContext when executing the timerjob function but I get "Instance reference is not set to an instance of an object". It fails when I reference SPContext.

What am I doing wrong? (I'm trying to update items in a list using a TimerJob)

Public Overrides Sub Execute(ByVal targetInstanceId As Guid)

   Dim oWeb As SPWeb = SPContext.Current.Web

   'Update PEEIT Employees List

End Sub
share|improve this question
Please accept the answer if it resolves, yours is 0% (Accept rate) – Vamsi Nov 7 '11 at 20:04

SPContext is not accessible in timer job. The SharePoint timer service is a windows service. So you should pass a site and web Ids(Urls) to the timer job and open new web.

using(SPSite site = new SPSite(siteId)){using(SPWeb web = site.OpenWeb(webId)) { //code }}
share|improve this answer

SPContext represents the context of a HTTPRequest (Similar to HTTPContext).

In the Execute method, SPWebApplication instance is available ; get the target site instance from the this.WebApplication.Sites collection.


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.