abpframework/abp · error · AbpException

There is no active UOW.

Error message

There is no active UOW.

What it means

Same guard as in DistributedCache, duplicated in the Hybrid cache implementation (AbpHybridCache). GetUnitOfWorkCache throws when IUnitOfWorkManager.Current is null because the hybrid cache also tracks per-UOW changes so reads/writes stay consistent with the in-flight transaction before flushing to the distributed cache.

Source

Thrown at framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Hybrid/AbpHybridCache.cs:426

                .NotifyAsync(new ExceptionNotificationContext(ex, LogLevel.Warning));
        }
    }

    protected virtual bool ShouldConsiderUow(bool considerUow)
    {
        return considerUow && UnitOfWorkManager.Current != null;
    }

    protected virtual string GetUnitOfWorkCacheKey()
    {
        return UowCacheName + CacheName;
    }

    protected virtual Dictionary<TCacheKey, UnitOfWorkCacheItem<TCacheItem>> GetUnitOfWorkCache()
    {
        if (UnitOfWorkManager.Current == null)
        {
            throw new AbpException($"There is no active UOW.");
        }

        return UnitOfWorkManager.Current.GetOrAddItem(GetUnitOfWorkCacheKey(),
            key => new Dictionary<TCacheKey, UnitOfWorkCacheItem<TCacheItem>>());
    }

    private readonly ConcurrentDictionary<Type, object> _serializersCache = new();

    protected virtual IHybridCacheSerializer<TCacheItem> ResolveSerializer()
    {
        if (_serializersCache.TryGetValue(typeof(TCacheItem), out var serializer))
        {
            return serializer.As<IHybridCacheSerializer<TCacheItem>>();
        }

        serializer = ServiceProvider.GetService<IHybridCacheSerializer<TCacheItem>>();
        if (serializer is null)
        {

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Begin a unit of work before interacting with the hybrid cache: await using var uow = UnitOfWorkManager.Begin(requiresNew: true); ... await uow.CompleteAsync();
  2. Disable UOW consideration for the call if transactional consistency is not required.
  3. Ensure background services explicitly create a UOW scope (they do not inherit one like HTTP request handlers do).
  4. Register the cache-using service as transient/scoped so it resolves within the correct UOW-aware DI scope.

Example fix

// before: hybrid cache used in a hosted service with no UOW
public async Task RunAsync()
{
    await _hybridCache.SetAsync(key, value); // throws: no active UOW
}

// after: open a unit of work inside the background worker
public async Task RunAsync()
{
    await using (var uow = _unitOfWorkManager.Begin(requiresNew: true))
    {
        await _hybridCache.SetAsync(key, value);
        await uow.CompleteAsync();
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Gate hybrid cache UOW participation on an active UOW.
if (unitOfWorkManager.Current == null)
{
    // Either open a UOW or operate without UOW consideration.
    await using var uow = unitOfWorkManager.Begin(requiresNew: true);
    await hybridCache.SetAsync(key, value);
    await uow.CompleteAsync();
}
else
{
    await hybridCache.SetAsync(key, value);
}

Type guard

public static bool HasActiveUnitOfWork(IUnitOfWorkManager uowManager) =>
    uowManager.Current is not null;

Try / catch

try
{
    await hybridCache.SetAsync(key, value);
}
catch (AbpException ex) when (ex.Message.Contains("no active UOW", StringComparison.Ordinal))
{
    logger.LogWarning(ex, "Hybrid cache call outside UOW; opening one and retrying.");
    await using var uow = unitOfWorkManager.Begin(requiresNew: true);
    await hybridCache.SetAsync(key, value);
    await uow.CompleteAsync();
}

Prevention

When it happens

Trigger: AbpHybridCache invokes GetUnitOfWorkCache while UnitOfWorkManager.Current is null. Reachable when a caller uses the hybrid cache with UOW consideration enabled outside of any active unit of work, or via an internal flush path that assumes a UOW exists.

Common situations: Using IHybridCache from a background job/hosted service without beginning a UOW; calling cache methods that default to considerUow=true outside a request; migrating from IDistributedCache to hybrid cache without auditing UOW usage in non-request code paths.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/56420f1ee4df8b58. Report an issue: GitHub.