1
votes

I hate SharePoint.

I am trying to install a SharePoint timer via a feature. My feature is scoped as Web (scoping to WebApplication gives me an Access Denied error when I try and deploy).

My 2 constructors in timer class:

public CheckListForOldItems() : base()
{

}

public CheckListForOldItems(SPWebApplication webApp) : 
          base(JOB_NAME, webApp, null, SPJobLockType.Job)
{
    Title = "Check list for items which have not been modified recently.";
}

In the event receiver for FeatureActivated event I have

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
    CheckListForOldItems simpleJob = new CheckListForOldItems(webApp);

    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 1;

    simpleJob.Schedule = schedule;
    simpleJob.Update();
}

The project is set to no active deployment.

In SP when I activate the feature I get an error saying "An unexpected error has occurred. Correlation ID: bd1d16f6-e7c9-46c6-9a06-9103bd37858f

If I uncomment all lines of code in FeatureActivated except for the first one it activates without error, so it dies at the class declaration line.

What am I doing wrong?

2
have you checked sharepoint log with this " Correlation ID"Mahmoud Farahat
Where do I find the log?andrewb
In your 14 Hive: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGSMarco
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\logs then sort files by newest descending , more details about this id will be in the newest fileMahmoud Farahat
Object reference not set to an instance of an object is the helpful error. Is that because the feature scope is set to Web but the code sets webApp to WebApplication?andrewb

2 Answers

0
votes

Your feature is scope to Web.But in your code you are trying to convert a SPWeb object ie (properties.Feature.Parent) as SPWebApplication , which is wrong. Below line is wrong for Web Scoped feature:

SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

You can change the scope to Web Application(ideal way) or change the code to as below:

SPWeb web=properties.Feature.Parent as SPWeb;
CheckListForOldItems simpleJob = new CheckListForOldItems(web.Site.WebApplication);
0
votes

Timer Jobs should always be installed on Web Application level! Otherwise you're bound to get Access Denied messages.

Place your feature receiver code to install the Timer Job in a WebApplication scoped feature and it will work.