Can't Enqueue my Job in hangfire server

920 Views Asked by At

I am working on enqueue jobs using hangfire in my application.

my enqueue job statement is given below,

string jobId = BackgroundJob.Enqueue(() => 
     strategy.get(typeof(_service.Engine.Summary), cpdata));

when this will enqueue my job successfully but got the error message in State table like this,

"FailedAt": "2018-03-21T13:14:46.0172303Z", "ExceptionType": "System.MissingMethodException", "ExceptionMessage": "No parameterless constructor defined for this object.",
"ExceptionDetails": "System.MissingMethodException: No parameterless constructor defined for this object.\r\n at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n at System.Activator.CreateInstance(Type type)\r\n at Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type)\r\n
at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)\r\n at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass8_0.b__0()\r\n at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func 1 continuation)\r\n at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable`1 filters)\r\n at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context)\r\n at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)"

Is this DI issue that creating this type of error?

i used calling method in Enqueue using the reference of this link

Factory method with DI and IOC

For Example,

var strategy = new CarStrategy(new ICarFactory[] {
    new Car1Factory(dep1, dep2, dep3),
    new Car2Factory(dep4, dep5, dep6),
    new Car3Factory(dep7, dep8, dep9)
});

My Code is Like this,

var strategy = new Strategy(new ICP[] {
                new _Services.Engine.Detail.Detail(),
                new _1Services.Engine.Summary.Summary(),
                });

var CP = PrepareCPModelForEngine(c);

string jobId = BackgroundJob.Enqueue(() => 
strategy.get(typeof(_Services.Engine.Summary.Summary), cp));
0

There are 0 best solutions below