Timer Job not getting deployed in Sharepoint 2013

Hi,

I am creating a Timer Job in Sharepoint 2013 using the below mentioned links:

 - http://www.splessons.com/2013/12/create-a-timer-job-in-sharepoint-2013/
 - http://www.codeproject.com/Tips/634208/Create-and-Deploy-Custom-Timer-Job-Definition-in-S

My solution is getting deployed and I can activate/deactivate feature from Central Admin. But the timer job is not appearing in CA.

When I attached the debugger at the Timer Job's class file, it gets goes only to the first constructor. i.e. at the non parameterized constructor.
The debugger does not go to the other 2 constructors.
Moreover, when I try to debug the Feature's event receiver the debugger does not stops at the code, it only stops at the Timer Job's class file.

I am doing it with all the administrator rights.

Any help!!

My Event Receiver Code is :

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SharePointProj4.Features.Feature1
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("6f5a5ed1-98d3-4cde-a497-deef1b3b1467")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.
        const string JobName = "SP Task Timer";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWebApplication parentWebApp = (SPWebApplication)properties.Feature.Parent;
                    SPSite site = properties.Feature.Parent as SPSite;
                    DeleteExistingJob(JobName, parentWebApp);
                    CreateJob(parentWebApp);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            lock (this)
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        SPWebApplication parentWebApp = (SPWebApplication)properties.Feature.Parent;
                        DeleteExistingJob(JobName, parentWebApp);
                    });
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }


        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;
            try
            {
                SPJobs.SPTImerJobClass job = new SPJobs.SPTImerJobClass(JobName, site, "http://win-njfp7te48bn/");
                //SPJobs.SPTImerJobClass job = new SPJobs.SPTImerJobClass(JobName, site);
                SPMinuteSchedule schedule = new SPMinuteSchedule();
                schedule.BeginSecond = 0;
                schedule.EndSecond = 59;
                schedule.Interval = 15;
                job.Schedule = schedule;

                job.Update();
            }
            catch (Exception)
            {
                return jobCreated;
            }
            return jobCreated;
        }
        public bool DeleteExistingJob(string jobName, SPWebApplication site)
        {
            bool jobDeleted = false;
            try
            {
                foreach (SPJobDefinition job in site.JobDefinitions)
                {
                    if (job.Name == jobName)
                    {
                        job.Delete();
                        jobDeleted = true;
                    }
                }
            }
            catch (Exception)
            {
                return jobDeleted;
            }
            return jobDeleted;
        }

        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}


and my TimerJob Code is :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SharePointProj4.SPJobs
{
    class SPTImerJobClass : SPJobDefinition
    {
        public SPTImerJobClass() : base() { }

        public SPTImerJobClass(string jobName, SPService service) : base(jobName, service, null, SPJobLockType.None)
        {
            this.Title = jobName;
        }

        public SPTImerJobClass(string jobName, SPWebApplication webapp) : base(jobName, webapp, null, SPJobLockType.ContentDatabase)
        {
            this.Title = jobName;
        }

        public override void Execute(Guid targetInstanceId)
        {
            SPWebApplication webapp = this.Parent as SPWebApplication;
            SPList tasklist = webapp.Sites[0].RootWeb.Lists["Tasks1"];
            SPListItem newTask = tasklist.Items.Add();
            newTask["Title"] = "New Task" + DateTime.Now.ToString();
            newTask.Update();
        }
    }
}

September 7th, 2015 6:37am

Issue seems clearly on the feature receiver side.

Check the receiver assembly and receiver class within the feature with the actual one. Are both ok?

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 7:34am

Issue seems clearly on the feature receiver side.

Check the receiver assembly and receiver class within the feature with the actual one. Are bo

September 7th, 2015 7:46am

Can you also check in the feature declaration (feature.xml) that you have receiver assembly reference included?

Like

ReceiverAssembly="MyFeatureReceiver, 
  Version=1.0.0.0, 
  Culture=neutral, 
  PublicKeyToken=2f2197d99d6e2871" 
  ReceiverClass="FeatureReceiver.TestFeatureReceiver"

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 7:49am

Can you also check in the feature declaration (feature.xml) that you have receiver assembly reference included?

Like

ReceiverAssembly="MyFeatureReceiver, 
  Version=1.0.0.0, 
  Culture=neutral, 
  PublicKeyToken=2f2197d99d6e2871" 
  ReceiverClass="FeatureReceiver.TestFeatureReceiver"

September 7th, 2015 8:40am


Edit the menifest and update the feature assembly with above attributes.

your receiver class key value should be "SharePointProj4.Features.Feature1.Feature1EventReceiver " and open assembly and check the assembly named "SharePointProj4.Features.Feature1" and add its detail like version, token as described format at above.

Just for your info, refer this link for all the feature element properties.

https://msdn.microsoft.com/en-us/library/office/ms436075.aspx?f=255&MSPPError=-2147217396

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 9:12am


Edit the menifest and update the feature assembly with above attributes.

your receiver class key value should be "SharePointProj4.Features.Feature1.Feature1EventReceiver " and open assembly and check the assembly named "SharePointProj4.Features.Feature1" and add its detail like version, token as described format at above.

Just for your info, refer this link for all the feature element properties.

https://msdn.microsoft.com/en-us/library/office/ms436075.aspx?f=255&MSPPError=-2147217396

September 7th, 2015 9:57am

Do change Feature1.feature as thats the xml. Go to feature designer and edit it, add receiver assembly and its class into it.

Check as below shown in Manifest whether receiver assembly attribute is there or not in that feature.PackageExplorer

Free Windows Admin Tool Kit Click here and download it now
September 8th, 2015 3:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics