I have the following problem when trying to create a timer job
I created my job based on this article: http://msdn.microsoft.com/en-us/library/hh528519.aspx
However, debugging the feature activated event, I got a Sequence Contains No Elements exception on this code:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
// Get an instance of the SharePoint farm.
SPFarm farm = SPFarm.Local;
// Get an instance of the service.
var results = from s in farm.Services
where s.Name == "SynchronizationUserAccessListJob"
select s;
SPService service = results.First();
// Remove job if it exists.
DeleteJob(service);
// Create the job.
SynchronizationUserAccessListJob job = new SynchronizationUserAccessListJob(
"SynchronizationUserAccessListJob" , service);
// Create the schedule so that the job runs hourly, sometime
// during the first quarter of the hour.
SPHourlySchedule schedule = new SPHourlySchedule();
schedule.BeginMinute = 0;
schedule.EndMinute = 5;
job.Update();
}
When I reviewed the farm.Services collection in the debugger, in fact my new timer job is not there.
To install it I: 1. Add-SPSolution 2. Install-SPSolution 3. Enable the feature on central administration farm feature.
What else am I missing??
If somebody ask me I would say the code provided in that article is wrong, It should check first if it the linq query returns result, if Not, then it should create an instance of the object
Right or wrong?