I'm getting this error when I browse my application with Quartz.NET and MVC4.
Inheritance security rules violated while overriding member: 'Quartz.Core.QuartzScheduler.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
I can't undestand what's going on.
My code in Global.asax:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
BuildQuartzScheduler();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
private void BuildQuartzScheduler()
{
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
IJobDetail job = JobBuilder.Create<AlertasJob>().WithIdentity("AlertasJob").Build();
ITrigger morningTrigger = TriggerBuilder.Create()
.ForJob(job)
.WithCronSchedule("0 0 6 * * ?")
.WithIdentity("AlertaManhaTrigger")
.StartNow()
//.WithDailyTimeIntervalSchedule(x => x.WithIntervalInMinutes(2))
.Build();
ITrigger nightTrigger = TriggerBuilder.Create()
.ForJob(job)
.WithCronSchedule("0 0 23 * * ?")
.WithIdentity("AlertaNoiteTrigger")
.StartNow()
//.WithDailyTimeIntervalSchedule(x => x.WithIntervalInMinutes(2))
.Build();
var triggersList = new Quartz.Collection.HashSet<ITrigger>() { morningTrigger, nightTrigger };
sched.ScheduleJob(job, triggersList, true);
sched.Start();
}
}
AlertasJob class:
public class AlertasJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Parametro param = new Parametros.Parametro();
param.Obter();
VeriricarFuncionarioSemEPI(param);
}
public void VeriricarFuncionarioSemEPI(Parametro param)
{
DateTime? dataBusca = DateTime.Now;
using (Data.Server.SinsysEPIEntities context = new Data.Server.SinsysEPIEntities())
{
var funcs = context.Funcionarios
.Where(i => i.Funcao.ListaEPIs.Any());
foreach (var funcionario in funcs)
{
List<string> lstEPI = new List<string>();
foreach (var epi in funcionario.Funcao.ListaEPIs)
{
if (epi.EPI.DiasUso.HasValue)
{
var ir =
context.ItemRequisicaos
.Where(i => i.Requisicao.CodigoFuncionario == funcionario.Codigo)
.Where(i => i.EPI.Codigo == epi.CodigoEPI)
.Where(i => i.Devolvido == null || i.Devolvido == false)
.Where(i => i.Requisicao.Data.HasValue && i.Quantidade.HasValue)
.ToList()
.Where(i => i.Requisicao.Data.Value <= dataBusca || i.Requisicao.Data.Value >= dataBusca.Value.AddDays(-epi.EPI.DiasUso.Value * i.Quantidade.Value));
if (ir.Count() == 0)
lstEPI.Add(epi.EPI.Nome + "(CA " + epi.EPI.CA + ")");
}
}
if (lstEPI.Any())
{
var alerta = new AlertaFuncSemEPI(funcionario.Codigo, funcionario.Nome, funcionario.Funcao.Nome, lstEPI, param.EmailSemEPI);
}
}
}
}
}
Thanks for your help.