Open Closed

If hangfire is installed it wont run DBMigrator #9648


User avatar
0
tony.gayter created

Fairly straight forward, the DB migrator runs fine if I remove all the hangfire related code (the depends on and initialization bits). But if I add them back in I get the following

InvalidOperationException: Current JobStorage instance has not been initialized yet. You must set it before using Hangfire Client or Server API. For .NET Core applications please call the IServiceCollection.AddHangfire extension method from Hangfire.NetCore or Hangfire.AspNetCore package depending on your application type when configuring the services and ensure service-based APIs are used instead of static ones, like IBackgroundJobClient instead of BackgroundJob and IRecurringJobManager instead of RecurringJob.

Ive configured hangfire to use a seperate DB in case that was the issue but it didnt help. And hangfire is setup as standard with the SqlServer package.

I dont want to have to effectivly uninstall hangfire everytime I need to update the db (which is a lot during developement)


5 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • The error occurs because Hangfire requires its storage (JobStorage) to be initialized before any Hangfire API is used. When you add Hangfire dependencies and initialization code to your DbMigrator project, but do not configure Hangfire storage (via AddHangfire), it throws this exception.

    • The recommended approach is: Do not add Hangfire modules or initialization code to your DbMigrator project. The DbMigrator's purpose is to run database migrations and seed data, not to execute background jobs. Hangfire should only be configured in your main web host (or background worker) projects where background jobs are actually processed.

    • If you need to keep Hangfire NuGet packages for dependency reasons, ensure you do NOT call AddHangfire or add the Hangfire module in your DbMigrator. Remove any [DependsOn(typeof(AbpBackgroundJobsHangfireModule))] or similar from your DbMigrator module.

    • If you must share code between projects, use a shared library for job definitions, but keep Hangfire configuration and module dependencies out of the DbMigrator.

    • This is a common and recommended separation in ABP solutions:

      • Web/host project: Configures and runs Hangfire.
      • DbMigrator: Only runs migrations/seeding, no background job server.
    • You do not need to uninstall Hangfire from your solution—just ensure the DbMigrator project does not depend on or initialize Hangfire.

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    tony.gayter created

    Just in response to the AI message, Ive not touched the DBMigrator project, its as it was when I initialized the project

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can add the Hangfire module to the WEB/API.Host modules instead of the Domain module.

    Thanks.

  • User Avatar
    0
    tony.gayter created

    Thanks for pointing me in the right direction. I hadn't installed the module manually, I had used the cli as in the instructions

    abp add-package Volo.Abp.BackgroundJobs.HangFire

    But weirdly when I examined the installed packages it was in there and it has added it to the module class. After removing it from the packages and class it now runs. Thank-you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 12, 2025, 10:20