I Have weird problem intalling custom timer job definition to specific webapplication.
Environment is 2x wfe + 1x application server.
Development and staging works fine (single server boxes)
...method 'FeatureActivated' for feature '6ae97a43-a342-4f66-8416-2b492c88f896' threw an exception: Microsoft.SharePoint.SPException: (this is my custom error ->**Error occurred while installing Timer Job Definition) - **Error obtaining reference to Site - at MyTimerJob.TimerJobInstaller.FeatureActivated(SPFeatureReceiverProperties properties) at MyTimerJob.TimerJobInstaller.FeatureActivated(SPFeatureReceiverProperties properties) at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)
This happens when I try to activate my timer job feature. It does the same if I activate it from UI or from STSADM...
Here is the receiver code and feature.xml
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
const string featureGuid = "6ae97a43-a342-4f66-8416-2b492c88f896";
const string schedulePropertyName = "ScheduledRunTime";
// register the the current web
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
if (webApp == null)
{
throw new SPException("Error obtaining reference to context WebApplication");
}
//Verify and check if the job is already in place -> delete job
foreach (SPJobDefinition job in webApp.JobDefinitions)
{
if (job.Name == JOB_NAME)
job.Delete();
}
// install the job
MyTimerJob timerJob = new MyTimerJob(JOB_NAME, webApp) { IsDisabled = false };
//Time
SPFeatureDefinition timerJobFeature = GetFeatureProperties(featureGuid);
//Obtain schedule
SPSchedule schedule = SPSchedule.FromString(timerJobFeature.Properties[schedulePropertyName].Value);
//Declare schedule
timerJob.Schedule = schedule;
timerJob.Update();
}
catch (Exception ex)
{
throw new SPException("Error occurred while installing Timer Job Definition - " + ex.Message + " - " + ex.StackTrace);
}
}
private static SPFeatureDefinition GetFeatureProperties(string featureGuid)
{
if (featureGuid != null)
{
//Gets all farm features in the object
SPFeatureDefinitionCollection farmFeatures = SPFarm.Local.FeatureDefinitions;
//Gets specifiv feature with GUID
SPFeatureDefinition featureDefinition = farmFeatures[new Guid(featureGuid)];
//returns specific propertyValue
return featureDefinition;
}
return null;
}
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="6ae97a43-a342-4f66-8416-2b492c88f896"
Title="MyTimerJob"
Description="MyJob"
Scope="WebApplication"
Hidden="False"
Version="1.0.0.0"
ReceiverAssembly="MyTimerJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adc8d8d2b59e51ea"
ReceiverClass="MyTimer.TimerJobInstaller">
<Properties>
<Property Key="ScheduledRunTime" Value="every 1 minutes"/>
</Properties>
</Feature>