aspnetboilerplate/aspnetboilerplate · error · ArgumentException
unitOfWork is not type of…
Error message
unitOfWork is not type of Abp.EntityFrameworkCore.EfCoreUnitOfWork
What it means
After the null check, GetDbContextAsync requires the IActiveUnitOfWork to be an EfCoreUnitOfWork; EF Core DbContexts can only be created/tracked by the EF Core unit-of-work implementation. Passing a unit of work from another ORM (e.g. NHibernate, EntityFramework 6) throws this ArgumentException naming the expected type.
Solutions
- Ensure the Abp.EntityFrameworkCore module (and EfCoreUnitOfWork registration) is in use: register the EF Core data module for your DbContext assembly so IUnitOfWorkManager yields EfCoreUnitOfWork.
- Remove/replace registrations of other ORM unit-of-work implementations (NHibernate/Ef6) if you migrated to EF Core.
- Verify DbContext configurators/target assemblies point to EF Core repositories, not the other ORM.
- Check _unitOfWorkManager.Current's runtime type and confirm it is EfCoreUnitOfWork before calling.
Example fix
// before
// NHibernate module still registered; Current is NHibernateUnitOfWork
class AppNHibernateModule : AbpNHibernateModule { ... }
// after
public class AppModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(AppModule).GetAssembly());
Configuration.Modules.AbpEfCore().AddDbContext<AppDbContext>(...); // EfCoreUnitOfWork in use
}
} Defensive patterns
Strategy: type-guard
Validate before calling
if (_unitOfWorkManager.Current is not EfCoreUnitOfWork)
throw new InvalidOperationException($"Active UoW is {_unitOfWorkManager.Current?.GetType().Name}, expected EfCoreUnitOfWork — check ORM module registration."); Type guard
static bool IsEfCoreUow(IActiveUnitOfWork uow) => uow is EfCoreUnitOfWork;
Try / catch
try { var db = await uow.GetDbContextAsync<AppDbContext>(); }
catch (ArgumentException ex) when (ex.Message.Contains(nameof(EfCoreUnitOfWork)))
{
throw new InvalidOperationException("EF Core data module is not active; verify Abp.EntityFrameworkCore module registration.", ex);
} Prevention
- Install/register Abp.EntityFrameworkCore and configure AddDbContext for your contexts.
- Remove competing ORM unit-of-work modules (NHibernate, Ef6) when migrating.
- Assert the UoW runtime type in a startup smoke test.
- Use the extension from the package matching your ORM.
When it happens
Trigger: Calling unitOfWork.GetDbContextAsync<TDbContext>() (or sync GetDbContextAsync path) where the active unit of work was created by a different ABP data module — e.g. NHibernateUnitOfWork or the legacy EF6 UnitOfWork — because that module's package is installed/loaded instead of Abp.EntityFrameworkCore.
Common situations: Applications that migrated ORM but kept the old module registered, mixed ORM setups, or tests bootstrapped with the wrong module's unit-of-work registrar.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- unitOfWork
- unitOfWork is not type of…
- Can not set TenantId to 0 for IMustHaveTenant entities!
- Could not resolve DbContextOptions for
- Given job type does not implement IBackgroundJob<> or…
AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08).
Data as JSON: /api/errors/a90398474f949b67.
Report an issue: GitHub.
Appendix: source
Thrown at src/Abp.EntityFrameworkCore/EntityFrameworkCore/Uow/UnitOfWorkExtensions.cs:35
/// </summary>
/// <typeparam name="TDbContext">Type of the DbContext</typeparam>
/// <param name="unitOfWork">Current (active) unit of work</param>
/// <param name="multiTenancySide">Multitenancy side</param>
/// <param name="name">
/// A custom name for the dbcontext to get a named dbcontext.
/// If there is no dbcontext in this unit of work with given name, then a new one is created.
/// </param>
public static Task<TDbContext> GetDbContextAsync<TDbContext>(this IActiveUnitOfWork unitOfWork, MultiTenancySides? multiTenancySide = null, string name = null)
where TDbContext : DbContext
{
if (unitOfWork == null)
{
throw new ArgumentNullException("unitOfWork");
}
if (!(unitOfWork is EfCoreUnitOfWork))
{
throw new ArgumentException("unitOfWork is not type of " + typeof(EfCoreUnitOfWork).FullName, "unitOfWork");
}
return (unitOfWork as EfCoreUnitOfWork).GetOrCreateDbContextAsync<TDbContext>(multiTenancySide, name);
}
public static TDbContext GetDbContext<TDbContext>(this IActiveUnitOfWork unitOfWork, MultiTenancySides? multiTenancySide = null, string name = null)
where TDbContext : DbContext
{
if (unitOfWork == null)
{
throw new ArgumentNullException("unitOfWork");
}
if (!(unitOfWork is EfCoreUnitOfWork))
{
throw new ArgumentException("unitOfWork is not type of " + typeof(EfCoreUnitOfWork).FullName, "unitOfWork");
}
View on GitHub (pinned to 2323c13a15)