0
votes

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.

1
Can you provide the implementation of AlertasJob class?David
David, I have edited the post with the class implementation! Thx!!!arturcosta88

1 Answers

0
votes

Ive migrated all our Quartz.Net codebase away from Asp.Net for these kind of reasons. Anyway - my first guess would be to look at the trust level your application is running at. If you are running at medium trust this could well be the issue.

A quick google for Quartz.Net and medium trust shows quite a few people with what appears to be similar symptoms. If this is the case, then sorry I can't offer any advice beyond moving away from Asp.Net as your host.