SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Microsoft online code analysis framework , as we know i used to analyze the code [.wsp]

My code contains the timer job which is activated via feature. After running the MSOCAF on my WSP , i get warning as :

Implementation of Timer Job

Resolution : FeatureActivated event of SPFeatureReceiver does not contain the definition for job exist check. First verify if there exist any job with the same name. If exists delete the existing job and then use the new.

Code :

// make sure the job isn't already registered
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
    if (job.Name == TASK_LOGGER_JOB_NAME)

Let me know how to delete job so as to remove the MSOCAF warning.

share|improve this question

Looking at the rule's internals using Reflector tells me you are required to pass the following, in order for the rule not to trigger:

You must use (in FeatureActivated):

  • Call new Microsoft.SharePoint.SPMinuteSchedule()
  • and Get Microsoft.SharePoint.Administration.SPJobDefinition.Schedule
  • and Call Microsoft.SharePoint.Administration.SPPersistedObject.Update
  • and Get Microsoft.SharePoint.Administration.SPWebApplication.JobDefinitions

You must use (in FeatureDeactivated):

  • Get Microsoft.SharePoint.Administration.SPWebApplication.JobDefinitions
  • and Call Microsoft.SharePoint.Administration.SPPersistedObject.Delete

Exactly how to write the code isn't specified in the code of the rule.

But I'm guessing this will come close:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.