0

I've developed a timer job for one of my SharePoint web applications. I have written my job from SPJobdefinition class:

public class EraseUsersJob : SPJobDefinition
    {
        #region constants
        public struct Constantes
        {
            public const string JOB_NAME = "EraseUsers";
            public const string JOB_TITLE = "Erase Users";
        }
        #endregion

        #region constructors
        public EraseUsersJob() : base() { }

        public EraseUsersJob(string jobName,
                       SPService service,
                       SPServer server,
                       SPJobLockType targetType)
            : base(jobName, service, server, targetType) { }

        public EraseUsersJob(SPWebApplication webApplication)
            : this(Constantes.JOB_NAME, webApplication)
        {
        }

        public EraseUsersJob(string jobName, SPWebApplication webApplication)
            : base(jobName, webApplication, null, SPJobLockType.Job)
        {
            this.Title = Constantes.JOB_TITLE;
        }
        #endregion

        #region override
        public override void Execute(Guid targetInstanceId)
        {
        //my code
        }
        // my private methods used in execute() method

Then within a console program a create a new instance of this job using the constructor with the SPWebApplication argument. Then i set a schedule for my job and update it. My problem is that when i check if my Timer Job has been created in the SharePoint administration i find that it has not been created. Am i missing something? If you need more details or further information I will provide it to you.

Here's my Program.cs:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            SPWebApplication webApplication = SPWebApplication.Lookup(new Uri("http://XXXXX:80"));
            //Console.WriteLine("Installing EraseUsers job  ...");
            JobManager jobsManager = new JobManager();
            jobsManager.ApplyJobs(webApplication);
        }
        catch (Exception e)
        {
            Console.WriteLine("ERROR: "+e.Message);
        }

    }

Here's my job manager class:

public class JobManager : DeployJobHelper 
{
    public void ApplyJobs(SPWebApplication webApplication) 
    {            
        try
        {
            Console.WriteLine("         Installing EraseUsersJob");
            EraseUsersJob eraseUsersJob= new EraseUsersJob(webApplication);
            this.ApplyJob(webApplication, eraseUsersJob);
        }
        catch (Exception ex)
        {
            Console.WriteLine("                 Error: " + ex.Message + " // " + ex.StackTrace);
        }

        Console.WriteLine("         Job installation finished.");
    }
}

Here's my DeployHelper.cs:

public class DeployJobHelper
{
 protected void ApplyJob(SPWebApplication webApplication, SPJobDefinition jobDefinition)
    {
        string jobName = jobDefinition.Name;
        // delete previous Job definition
        webApplication.DeleteJobByName(jobName);
        //Install Job
        jobDefinition.Schedule = new SPMinuteSchedule() { BeginSecond=0, EndSecond=50,Interval=2 }; //GetScheduleValue(jobName);
        jobDefinition.Update();
    }
}

Moreover i've seen this error in the ULS:

SharePoint cannot deserialize an object of type XyZ.AbC.EraseUsersJob.EraseUsersJob, XyZ.AbC.EraseUsersJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null on this machine.  This typically occurs because the assembly containing this type is not installed on this machine.  In this case, this message can be safely ignored.  Otherwise, the assembly needs to be installed on this machine in a location that can be discovered by the .NET Framework.

I've read this error has something to do with either restarting Windows Sharepoint Services Timer or with namespace issues. I've already restarted my Windows SharePoint Services Timer and all my classes are wrapped within XyZ.AbC.EraseUsersJob namespace.

  • have you added the feature at web application level for that timerjob – Niranjan Kulkarni Jun 18 '15 at 10:12
  • Why would i need to use a feature if my JobManager class deals with the job instantiation and also sets the schedule to my timer job? Note: When i loop through my webApplication jobs i can retrieve my job but as i say i can't see it in my Job's list. – ERed Jun 18 '15 at 10:38
  • We need to add the feature at webapplication level inorder to deploy timerjob check the link, codeproject.com/Tips/634208/… – Niranjan Kulkarni Jun 18 '15 at 10:43
  • Also you can check, sharepointpals.com/post/… – Niranjan Kulkarni Jun 18 '15 at 10:43
  • Niranjan kulkarni, there's no need to use a feature to install a job. I mean, you can use it obviously, but it's not the only way to intall a job to your webApplication: msdn.microsoft.com/en-us/library/cc427068(v=office.12).aspx, check install jobs part. – ERed Jun 18 '15 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.