abpframework/abp · error · InvalidOperationException
No IHybridCacheSerializer configured for type '{typeof(TCach
Error message
No IHybridCacheSerializer configured for type '{typeof(TCacheItem).Name}' What it means
Thrown by AbpHybridCache.ResolveSerializer when no IHybridCacheSerializer<TCacheItem> can be resolved. The resolver first tries a directly registered serializer for the type, then iterates registered IHybridCacheSerializerFactory instances; if all return null, it throws. The hybrid cache must serialize cache items to the backing store, so every cached type needs a serializer.
Source
Thrown at framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Hybrid/AbpHybridCache.cs:459
serializer = ServiceProvider.GetService<IHybridCacheSerializer<TCacheItem>>();
if (serializer is null)
{
var factories = ServiceProvider.GetServices<IHybridCacheSerializerFactory>().ToArray();
Array.Reverse(factories);
foreach (var factory in factories)
{
if (factory.TryCreateSerializer<TCacheItem>(out var current))
{
serializer = current;
break;
}
}
}
if (serializer is null)
{
throw new InvalidOperationException($"No {nameof(IHybridCacheSerializer<TCacheItem>)} configured for type '{typeof(TCacheItem).Name}'");
}
return serializer.As<IHybridCacheSerializer<TCacheItem>>();
}
}
View on GitHub (pinned to 7ed43b1931)
Solutions
- Register an IHybridCacheSerializer<TCacheItem> for the type: context.Services.AddTransient<IHybridCacheSerializer<MyDto>, MyDtoSerializer>();
- Or register/enable an IHybridCacheSerializerFactory whose TryCreateSerializer<T> returns true for the type (the JSON factory covers most serializable DTOs).
- Ensure the type is JSON-serializable (public parameterless constructor, serializable members) so the default factory can handle it.
- Add the AbpHybridCache module and its default serializer configuration via the proper module dependency.
Example fix
// before: caching MyDto with no serializer configured
public class MyDto { public string Name { get; set; } }
// _hybridCache.GetAsync<MyDto>(...) throws InvalidOperationException
// after: register a serializer (or ensure the JSON factory covers it)
context.Services.AddSingleton<IHybridCacheSerializer<MyDto>, JsonHybridCacheSerializer<MyDto>>();
// or register a factory that handles arbitrary types
context.Services.AddSingleton<IHybridCacheSerializerFactory, JsonHybridCacheSerializerFactory>(); Defensive patterns
Strategy: validation
Validate before calling
// Before caching a type, ensure a serializer (or a factory that can build one) is registered.
var direct = serviceProvider.GetService<IHybridCacheSerializer<TCacheItem>>();
var factoryCanHandle = serviceProvider.GetServices<IHybridCacheSerializerFactory>()
.Any(f => f.TryCreateSerializer<TCacheItem>(out _));
if (direct == null && !factoryCanHandle)
{
throw new InvalidOperationException($"No IHybridCacheSerializer<{typeof(TCacheItem).Name}> registered. Register one or an IHybridCacheSerializerFactory.");
} Type guard
public static bool HasSerializerFor<TCacheItem>(IServiceProvider sp)
{
if (sp.GetService<IHybridCacheSerializer<TCacheItem>>() is not null) return true;
return sp.GetServices<IHybridCacheSerializerFactory>().Any(f => f.TryCreateSerializer<TCacheItem>(out _));
} Try / catch
try
{
var value = await hybridCache.GetAsync<TCacheItem>(key);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("No IHybridCacheSerializer", StringComparison.Ordinal))
{
logger.LogError(ex, "Missing hybrid cache serializer for {Type}; register one and retry.", typeof(TCacheItem).Name);
throw;
} Prevention
- Register serializers (or a JSON factory) for every type you cache with the hybrid cache.
- Ensure cached DTOs are JSON-serializable (public, parameterless constructor).
- Add a startup test that resolves a serializer for each cached type.
- Keep the AbpHybridCache module and its default serializer factory in DependsOn.
When it happens
Trigger: AbpHybridCache<TCacheKey, TCacheItem> performs a get/set that requires serialization, and the DI container has neither IHybridCacheSerializer<TCacheItem> nor any IHybridCacheSerializerFactory that can build one for TCacheItem. The cached type was never registered with the hybrid cache serializer infrastructure.
Common situations: Caching a custom DTO with the hybrid cache without registering a serializer or factory; enabling AbpHybridCache module but not configuring serializers; removing the default JSON serializer factory; caching a type that the default factory cannot handle (e.g., lacks a parameterless constructor or is not JSON-serializable).
Related errors
- There is no active UOW.
- code length overflow. (${buffer.getLengthInBits()}>${totalDa
- Expected Dapr App API Token is not provided! Dapr should set
- The Dapr App API Token (provided in the 'dapr-api-token' HTT
- Background job execution is disabled. This method should not
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/aacc2c0e4bc127f6.
Report an issue: GitHub.