我们刚刚将hangfire从1.3.4更新为1.5.3。我们的创业公司已从此更改: private static void DoHangfire(IAppBuilder app) { var options = new BackgroundJobServerOptions { // Set thread count to 1 WorkerCount = 1 }; app.UseHangfire(config => { config.UseSqlServerStorage(ConfigurationManager.ConnectionStrings["JobsDB"].ConnectionString); config.UseAuthorizationFilters(new HangfireDashboardAuthorizationFilter()); config.UseServer(options); }); // Set retries to zero GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); JobActivator.Current = new WindsorJobActivator(Container.Kernel); }对此: private static void DoHangfire(IAppBuilder app) { var options = new BackgroundJobServerOptions { // Set thread count to 1 WorkerCount = 1 }; GlobalConfiguration.Configuration.UseSqlServerStorage( ConfigurationManager.ConnectionStrings["JobsDB"].ConnectionString); app.UseHangfireDashboard("/hangfire", new DashboardOptions() { AuthorizationFilters = new List<IAuthorizationFilter> { new HangfireDashboardAuthorizationFilter() } }); app.UseHangfireServer(options); // Set retries to zero GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); JobActivator.Current = new WindsorJobActivator(Container.Kernel); }现在,我们所有的工作(我们有4种不同的工作)都会立即由于以下错误而失败:  System.MissingMethodException:未定义无参数构造函数  对于这个对象。在  System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,布尔  publicOnly,布尔值noCheck,布尔值和canBeCached,  RuntimeMethodHandleInternal&ctor,Boolean&bNeedSecurityCheck),位于  System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔  skipCheckThis,布尔值fillCache,StackCrawlMark和stackMark)  System.RuntimeType.CreateInstanceDefaultCtor(布尔publicOnly,  布尔skipCheckThis,布尔fillCache,StackCrawlMark和stackMark)  在System.Activator.CreateInstance(Type type,Boolean nonPublic)在  System.Activator.CreateInstance(Type type)位于  Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type)在  Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext  上下文)  Hangfire.Server.BackgroundJobPerformer。 c__DisplayClass3.b__0()  在  Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter  过滤器,PerformingContext preContext,Func 1 continuation) at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable 1过滤器)位于  Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext上下文)  在Hangfire.Server.Worker.PerformJob(BackgroundProcessContext上下文,  IStorageConnection连接,字符串jobId) 最佳答案 好吧,这个问题与新版本的Hangfire如何与Hangfire.Windsor软件包交互产生了神奇的联系,该软件包只是为自定义JobActivator提供了带有温莎容器的服务位置。通过移动JobActivator.Current = new WindsorJobActivator(Container.Kernel);在对app.UseHangfireServer()调用的上方,我们能够发现真正的异常消息,这是Castle.MicroKernel.ComponentNotFoundException,通知我们它无法加入包含我们想要执行hangfire的方法的依赖项。足以说,在1.3.4中,要执行一项工作,您可以执行以下操作:BackgroundJob.Enqueue(() => thingWhichDoesStuff.DoStuff());在这里,thingWhichDoesStuff被注入到包含的类中,而hangfire.windsor JobActivator能够神奇地解析为该类型。但是,在1.5.3中,这种神奇的解决方法不再发生,因此您必须显式地告诉JobActivator接口,该接口包含要运行hangfire的方法的类型:BackgroundJob.Enqueue<IDoStuff>(x => x.DoStuff());这将导致我们所有的工作重新开始。关于c# - 我们所有工作上的Hangfire 1.5.3 System.MissingMethodException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35088769/
10-12 23:34