abpframework/abp · error · Exception
Could not find an object of {typeof(T).AssemblyQualifiedName
Error message
Could not find an object of {typeof(T).AssemblyQualifiedName} in services. Be sure that you have used AddObjectAccessor before! What it means
Thrown by ServiceCollectionObjectAccessorExtensions.GetObject<T> when no IObjectAccessor<T> has been registered (so the underlying value is null). The message reminds the caller to call AddObjectAccessor first. This is the read-side counterpart to error 233.
Source
Thrown at framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionObjectAccessorExtensions.cs:52
}
//Add to the beginning for fast retrieve
services.Insert(0, ServiceDescriptor.Singleton(typeof(ObjectAccessor<T>), accessor));
services.Insert(0, ServiceDescriptor.Singleton(typeof(IObjectAccessor<T>), accessor));
return accessor;
}
public static T? GetObjectOrNull<T>(this IServiceCollection services)
where T : class
{
return services.GetSingletonInstanceOrNull<IObjectAccessor<T>>()?.Value;
}
public static T GetObject<T>(this IServiceCollection services)
where T : class
{
return services.GetObjectOrNull<T>() ?? throw new Exception($"Could not find an object of {typeof(T).AssemblyQualifiedName} in services. Be sure that you have used AddObjectAccessor before!");
}
}
View on GitHub (pinned to 7ed43b1931)
Solutions
- Register the accessor with AddObjectAccessor<T>() / TryAddObjectAccessor<T>() before calling GetObject<T>().
- Use GetObjectOrNull<T>() if the value may legitimately be absent and handle the null case.
- Reorder startup so the accessor is populated before dependent code reads it (often move the read into OnApplicationInitialization).
Example fix
// before — accessor never added var cfg = services.GetObject<IConfiguration>(); // after — register first services.AddObjectAccessor<IConfiguration>(myConfiguration); var cfg = services.GetObject<IConfiguration>(); // or tolerate absence var cfg = services.GetObjectOrNull<IConfiguration>();
Defensive patterns
Strategy: validation
Validate before calling
// Use the OrNull variant and register the accessor first when needed
var value = services.GetObjectOrNull<T>();
if (value == null)
{
services.TryAddObjectAccessor<T>();
// populate as needed, then read again
} Prevention
- Register the accessor (TryAddObjectAccessor) before reading it.
- Use GetObjectOrNull<T>() when absence is acceptable.
- Move reads into OnApplicationInitialization where accessors are populated.
When it happens
Trigger: Calling services.GetObject<T>() before any AddObjectAccessor<T>() has registered the accessor — e.g. reading IAbpHostEnvironment or IConfiguration during ConfigureServices before the host wired it.
Common situations: Accessing a framework accessor during module registration before the generic host has populated it; misordered startup; custom code resolving an accessor ABP never adds in the current hosting model.
Related errors
- An object accessor is registered before for type: {typeof(T)
- Could not find singleton service: {typeof(T).AssemblyQualifi
- Could not find {typeof(IServiceProviderFactory<TContainerBui
- Could not find an implementation of {typeof(IConfiguration).
- No BLOB Storage provider was registered! At least one provid
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/d8044d28f1dba356.
Report an issue: GitHub.