aspnetboilerplate/aspnetboilerplate · error · AbpException
Must set UnitOfWorkManager before use it.
Error message
Must set UnitOfWorkManager before use it.
What it means
BackgroundJobBase.UnitOfWorkManager is lazily accessed via a property that throws AbpException when the backing field is still null. In normal ABP dependency injection the property is property-injected by the framework; hitting this means the job instance was created outside DI (e.g. with 'new') or property injection failed.
Solutions
- Resolve the job through IIocResolver/IocManager (or let BackgroundJobManager create it) so ABP performs property injection
- Explicitly assign UnitOfWorkManager (e.g. from IocManager.Resolve<IUnitOfWorkManager>()) when constructing the job manually in tests
- Derive from BackgroundJob<TArgs> and register the job class so the framework injects its dependencies
Example fix
// before var job = new MyReportJob(); // UnitOfWorkManager never injected job.Execute(args); // after var job = IocManager.Instance.Resolve<MyReportJob>(); // property-injected job.Execute(args);
Defensive patterns
Strategy: validation
Validate before calling
if (job.UnitOfWorkManager == null)
job.UnitOfWorkManager = IocManager.Instance.Resolve<IUnitOfWorkManager>(); Type guard
bool CanRun(BackgroundJobBase job) => job.UnitOfWorkManager != null;
Try / catch
try { job.Execute(args); }
catch (AbpException ex) when (ex.Message.Contains("Must set UnitOfWorkManager"))
{
job.UnitOfWorkManager = IocManager.Instance.Resolve<IUnitOfWorkManager>();
job.Execute(args);
} Prevention
- Always resolve background jobs via IocManager/BackgroundJobManager, never 'new'
- In unit tests, set UnitOfWorkManager explicitly in the fixture setup
- Prefer inheriting BackgroundJob<TArgs> so ABP wires dependencies
When it happens
Trigger: Instantiating a BackgroundJob-derived class manually with 'new' instead of resolving it through ABP's IocManager; using the job in a context where ABP's property injection never ran (non-DI factory, unit test constructing the class directly).
Common situations: Unit tests new-ing up background jobs without supplying UnitOfWorkManager; custom job activation code bypassing the IocResolver used by BackgroundJobManager.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Could not resolve DbContextOptions for
- Given job type does not implement IBackgroundJob<> or…
- jobId
- Must set LocalizationSourceName before, in order to get…
- Must set UnitOfWorkManager before use it.
AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08).
Data as JSON: /api/errors/f09be73ca9eb73e8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Abp/BackgroundJobs/BackgroundJobBase.cs:26
namespace Abp.BackgroundJobs
{
public abstract class BackgroundJobBase<TArgs> : IBackgroundJobBase<TArgs>
{
/// <summary>
/// Reference to the setting manager.
/// </summary>
public ISettingManager SettingManager { protected get; set; }
/// <summary>
/// Reference to <see cref="IUnitOfWorkManager"/>.
/// </summary>
public IUnitOfWorkManager UnitOfWorkManager
{
get
{
if (_unitOfWorkManager == null)
{
throw new AbpException("Must set UnitOfWorkManager before use it.");
}
return _unitOfWorkManager;
}
set { _unitOfWorkManager = value; }
}
private IUnitOfWorkManager _unitOfWorkManager;
/// <summary>
/// Gets current unit of work.
/// </summary>
protected IActiveUnitOfWork CurrentUnitOfWork
{
get { return UnitOfWorkManager.Current; }
}
/// <summary>View on GitHub (pinned to 2323c13a15)