{"record":{"id":"a90398474f949b67","repo":"aspnetboilerplate/aspnetboilerplate","slug":"unitofwork-is-not-type-of-abp-entityframeworkcore","errorCode":null,"errorMessage":"unitOfWork is not type of Abp.EntityFrameworkCore.EfCoreUnitOfWork","messagePattern":"unitOfWork is not type of Abp\\.EntityFrameworkCore\\.EfCoreUnitOfWork","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Abp.EntityFrameworkCore/EntityFrameworkCore/Uow/UnitOfWorkExtensions.cs","lineNumber":35,"sourceCode":"    /// </summary>\n    /// <typeparam name=\"TDbContext\">Type of the DbContext</typeparam>\n    /// <param name=\"unitOfWork\">Current (active) unit of work</param>\n    /// <param name=\"multiTenancySide\">Multitenancy side</param>\n    /// <param name=\"name\">\n    /// A custom name for the dbcontext to get a named dbcontext.\n    /// If there is no dbcontext in this unit of work with given name, then a new one is created.\n    /// </param>\n    public static Task<TDbContext> GetDbContextAsync<TDbContext>(this IActiveUnitOfWork unitOfWork, MultiTenancySides? multiTenancySide = null, string name = null)\n        where TDbContext : DbContext\n    {\n        if (unitOfWork == null)\n        {\n            throw new ArgumentNullException(\"unitOfWork\");\n        }\n\n        if (!(unitOfWork is EfCoreUnitOfWork))\n        {\n            throw new ArgumentException(\"unitOfWork is not type of \" + typeof(EfCoreUnitOfWork).FullName, \"unitOfWork\");\n        }\n\n        return (unitOfWork as EfCoreUnitOfWork).GetOrCreateDbContextAsync<TDbContext>(multiTenancySide, name);\n    }\n\n    public static TDbContext GetDbContext<TDbContext>(this IActiveUnitOfWork unitOfWork, MultiTenancySides? multiTenancySide = null, string name = null)\n        where TDbContext : DbContext\n    {\n        if (unitOfWork == null)\n        {\n            throw new ArgumentNullException(\"unitOfWork\");\n        }\n\n        if (!(unitOfWork is EfCoreUnitOfWork))\n        {\n            throw new ArgumentException(\"unitOfWork is not type of \" + typeof(EfCoreUnitOfWork).FullName, \"unitOfWork\");\n        }\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp.EntityFrameworkCore/EntityFrameworkCore/Uow/UnitOfWorkExtensions.cs#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// NHibernate module still registered; Current is NHibernateUnitOfWork\nclass AppNHibernateModule : AbpNHibernateModule { ... }\n\n// after\npublic class AppModule : AbpModule\n{\n    public override void Initialize()\n    {\n        IocManager.RegisterAssemblyByConvention(typeof(AppModule).GetAssembly());\n        Configuration.Modules.AbpEfCore().AddDbContext<AppDbContext>(...); // EfCoreUnitOfWork in use\n    }\n}","handlingStrategy":"type-guard","validationCode":"if (_unitOfWorkManager.Current is not EfCoreUnitOfWork)\n    throw new InvalidOperationException($\"Active UoW is {_unitOfWorkManager.Current?.GetType().Name}, expected EfCoreUnitOfWork — check ORM module registration.\");","typeGuard":"static bool IsEfCoreUow(IActiveUnitOfWork uow) => uow is EfCoreUnitOfWork;","tryCatchPattern":"try { var db = await uow.GetDbContextAsync<AppDbContext>(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(nameof(EfCoreUnitOfWork)))\n{\n    throw new InvalidOperationException(\"EF Core data module is not active; verify Abp.EntityFrameworkCore module registration.\", ex);\n}","preventionTips":["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."],"tags":["unit-of-work","type-mismatch","entityframework-core","abp"],"backgroundTag":"type-mismatch","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}