Home c# Hangfire task is not working

Hangfire task is not working

Author

Date

Category

Hello everyone. I recently had to use Hangfire to launch a specific task.

When you start the task, I get this exception in the planner itself:

failed
An Exception Occurred During Processing Of A Background Job.
System.InvalidoperationException
A Suitable Constructor for Type 'SmsservicePanel.getInfoforResourseService' Could Not Be Located. Ensure The Type is Concrete and Services Are Registered for All Parameters of a Public Constructor.
System.InvalidOperationException: A Suitable Constructor for Type 'SMSServicePanel.getInfoforResourSeservice' Could Not Be Located. Ensure The Type is Concrete and Services Are Registered for All Parameters of a Public Constructor.
  AT Microsoft.Extensions.DependencyInjection.ActiveInsTorutiIs.CreateInstance (IServiceProvider Provider, Type InstanceType, Object [] Parameters)
  at Microsoft.Extensions.DependencyInjection.ActiveVatorutilities.GetServiceorcreateInsTance (IServiceProvider Provider, Type Type)
  at hangfire.aspnetcore.aspnetcorejobactivatorscope.resolve (Type Type)
  AT Hangfire.Server.CorebackGroundJobperformer.perform (PerformContext CONTEXT)
  at hangfire.server.backgroundjobperformer. & lt; & gt; c__displayclass9_0. & lt; Performjobwithfilters & gt; b__0 ()
  at Hangfire.Server.BackgroundJobperformer.invokeperformFilter (iServerFilter Filter, PerformingContext Precontext, Func`1 Continuation)
  at hangfire.server.backgroundjobperformer. & lt; & gt; c__displayclass9_1. & lt; Performjobwithfilters & gt; b__2 ()
  AT Hangfire.Server.BackgroundJobperformer.performJobwithfilters (PerformContext Context, Ienumerable`1 Filters)
  AT Hangfire.Server.BackGroundJobperformer.perform (PerformContext CONTEXT)
  at Hangfire.server.Worker.performJob (BackgroundProcessContext Connection, IStorageConnection Connection, String Jobid)

Here is the code of the whole task:

Public Class JSONSERIALIZE
{
  Public String Name {Get; SET; }
  Public String Count {Get; SET; }
}
Public Class GetInfoforResoursourseservice.
{
  Public EFUSERDBCONTEXT DB;
  Public IinfowithPanelRepository InfoWithPanelRepository;
  GetInfoforResourseService (EfuserDbContext DB, IinfowithPanelRepository InfoWithPanelRepository)
  {
    this.db = db;
    this.infowithpanelRepository = InfoWithPanelRepository;
  }
  Private Async Task & Lt; String & GT; Request ()
  {
    var appsettingsjson = appsettingsjson.getAppsettings ();
    var ip = appsettingsjson ["smsserviceip"];
    var apikey = appsettingsjson ["apikeysmsservice"];
    WebRequest Request = WebRequest.create ($ "http: // {} / Stubs/monitors_ajax.php");
    Request.method = "post"; // For sending Used POST method
                 // Data for sending
    STRING DATA = $ "api_key = {apikey}";
    // Transform data into an array of bytes
    byte [] bytearray = System.Text.Encoding.utf8.getBytes (DATA);
    // Install the content type - ContentType parameter
    Request.contentType = "Application / X-WWW-FORM-URLENCODED";
    // Install the Content-Length query header - the ContentLength property
    Request.contentLength = bytearray.Length;
    // write data into the query stream
    Using (Stream DataStream = Request.getRequeststReam ())
    {
      datastream.write (Bytearray, 0, bytearray.Length);
    }
    WEBRESPONSE RESPONSE = await request.getResponseAsync ();
    Stream Stream = Response.getResponseStream ();
    StreamReader Reader = New StreamReader (Stream);
    STRING RESULT = Reader.ReadToend ();
    response.close ();
    RETURN RESULT;
  }
  Public Async Task GetInfo ()
  {
    var jsonstring = await request ();
    Root result = jsonconvert.deserializeobject & lt; root & gt; (jsonstring);
    var resourceselist = new list & lt; jsonservialize & gt; ();
    Foreach (Var Item in Result.UnProcessed_requests)
    {
      var addeditem = new jsonserialize () {name = item.server_name, count = item.requests_count};
      ResourSelist.add (AddedItem); 
}
    var json = system.text.json.jsonSerializer.serialize (ResourSelist);
    InfoWithPanel info = await db.infos.firstordefaultAltasync ();
    if (info == null)
    {
      var addedinfo = new infoWithPanel () {Resourses = JSON, LastUpdate = datetime.Now};
      infoWithPanelRepository.create (AddedInfo);
    }
    ELSE.
    {
      var updatedInfo = new infoWithPanel () {id = info.id, Resourses = JSON, LastUpdate = datetime.Now};
      infoWithPanelRepository.update (UpdatedInfo);
    }
    Return;
  }
}

}

What could be the problem?


Answer 1

Thank you guys from comments. I assigned a bublic availability modifier constructor and now everything worked.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions