Hanfire send sms

hi
please reply
hangfire on .net 4.8 ,It was implemented
It gives an exception :slightly_frowning_face:

Failed
An exception occurred during processing of a background job.

System.MissingMethodException
No parameterless constructor defined for this object.

System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Hangfire.JobActivator.ActivateJob(Type jobType)
at Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type)
at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass9_0.b__0()
at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func1 continuation) at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass9_1.<PerformJobWithFilters>b__2() at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable1 filters)
at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)

It looks like you don’t have dependency injection setup. The default job activator just uses Activator.CreateInstance as you can see in the stack trace.

1 Like

Thanks for your advice

I have written the
service “BackgroundService” with injection (DbContext and PayamakServise )
and this backgroundjob :
" BackgroundJob.Enqueue(x =>x.BackgroundSendPayamak(“Rahyab”, Message, user.PhoneNumber));"

It displays on the dashboard hangfire job:
// Job ID: #42
using Nick.Service.DataAccessService.Background;
var backgroundService = Activate();
backgroundService.BackgroundSendPayamak(
“Rahyab”,
“hi”
Message
,
“PHONE_NUMBER”);

But it gives this error again:
System.MissingMethodException: No parameterless constructor defined for this object.

Thanks

after success job1
job2 is:
BackgroundJob.ContinueJobWith(jobEmail,() => UpdateProductNotification(item), JobContinuationOptions.OnlyOnSucceededState);

error :slightly_frowning_face:

Unity.ResolutionFailedException

Resolution failed with error: No public constructor is available for type Nick.DataAccess.Infrastructure.IUnitOfWork. For more detailed information run Unity in debug mode: new UnityContainer(ModeFlags.Diagnostic)

Unity.ResolutionFailedException: Resolution failed with error: No public constructor is available for type Nick.DataAccess.Infrastructure.IUnitOfWork.