0

Trying to execute the Update method on a SPJobDefinition object, I notice that it recall the "empty Constructor" and returns me the following error:

An object of the type SendMailDaily.SendMailDaily named "SendMailDaily" already exists under the parent Microsoft.SharePoint.Administration.SPAdministrationWebApplication named "". Rename your object or delete the existing object.

Code:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        try
        {
            loggerObjFeature.writeLog("Begin");
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPWebApplication parentWebApp = (SPWebApplication)properties.Feature.Parent;
                SPSite site =  parentWebApp.Sites[0];
                //DeleteExistingJob(JobName, parentWebApp);
                CreateConfigList(site);
                CreateJob(parentWebApp);
            });
            loggerObjFeature.writeLog("End");
        }
        catch (Exception ex)
        {
            loggerObjFeature.writeLog("Errore:" + ex.Message);
            throw ex;
        }

    }
    private bool CreateJob(SPWebApplication site)
    {
        bool jobCreated = false;
        try
        {
            loggerObjFeature.writeLog("Begin");
            SendMailDaily job = new SendMailDaily(JobName, site);
            SPMinuteSchedule schedule = new SPMinuteSchedule();
            //schedule.BeginSecond = 0;
            //schedule.EndSecond = 59;
            //schedule.Interval = 15;
            job.Schedule = schedule;

            job.Update();
            loggerObjFeature.writeLog("End");
            return jobCreated;

        }
        catch (Exception ex)
        {
            loggerObjFeature.writeLog("Errore:" + ex.Message);
            return jobCreated;
        }

    }
  • where do you use this code? Please provide some more details – Nk SP Apr 21 '15 at 10:57
  • code Updated. I'm using it into the feature activation – hello B Apr 21 '15 at 11:00
0

Try to define this constructor:

public SendMailDaily SPWebApplication application)
    : base(JobName, application, null, SPJobLockType.Job)
{

}

and then use it:

SendMailDaily job = new SendMailDaily(site);

instead of

SendMailDaily job = new SendMailDaily(JobName, site);

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.