abpframework/abp · error · InvalidOperationException
Could not find singleton service: {typeof(T).AssemblyQualifi
Error message
Could not find singleton service: {typeof(T).AssemblyQualifiedName} What it means
Thrown by ServiceCollectionCommonExtensions.GetSingletonInstance<T> when no service descriptor with ServiceType == typeof(T) and an implementation instance exists in the collection. This is a hard InvalidOperationException used by internal ABP startup helpers that require a pre-built singleton (e.g. ITypeFinder, IAbpApplication) to be registered before they are accessed.
Source
Thrown at framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs:39
public static ITypeFinder GetTypeFinder(this IServiceCollection services)
{
return services.GetSingletonInstance<ITypeFinder>();
}
public static T? GetSingletonInstanceOrNull<T>(this IServiceCollection services)
{
return (T?)services
.FirstOrDefault(d => d.ServiceType == typeof(T))
?.NormalizedImplementationInstance();
}
public static T GetSingletonInstance<T>(this IServiceCollection services)
{
var service = services.GetSingletonInstanceOrNull<T>();
if (service == null)
{
throw new InvalidOperationException("Could not find singleton service: " + typeof(T).AssemblyQualifiedName);
}
return service;
}
public static IServiceProvider BuildServiceProviderFromFactory([NotNull] this IServiceCollection services)
{
Check.NotNull(services, nameof(services));
foreach (var service in services)
{
var factoryInterface = service.NormalizedImplementationInstance()?.GetType()
.GetTypeInfo()
.GetInterfaces()
.FirstOrDefault(i => i.GetTypeInfo().IsGenericType &&
i.GetGenericTypeDefinition() == typeof(IServiceProviderFactory<>));
if (factoryInterface == null)View on GitHub (pinned to 7ed43b1931)
Solutions
- Ensure AbpApplication.CreateAsync / AddAbp has run so the expected singleton (e.g. IAbpApplication, ITypeFinder) is registered before calling these helpers.
- Use the OrNull variant (GetSingletonInstanceOrNull<T>) if the singleton may legitimately be absent, and handle null.
- Check call ordering: these methods read the IServiceCollection, not the built provider, so the descriptor must exist at call time.
- If calling inside a module, move the access into OnApplicationInitialization (post-build) or use IServiceProvider resolution instead.
Example fix
// before — called before ITypeFinder is registered var finder = services.GetTypeFinder(); // after — register/initialize the ABP application first, then access var application = await AbpApplicationFactory.CreateAsync<YourModule>(services); var finder = services.GetTypeFinder();
Defensive patterns
Strategy: validation
Validate before calling
// Use the OrNull variant and branch on null rather than letting GetSingletonInstance throw
var finder = services.GetSingletonInstanceOrNull<ITypeFinder>();
if (finder == null)
throw new InvalidOperationException("ABP not initialized: ensure AbpApplicationFactory.CreateAsync ran."); Try / catch
try { var svc = services.GetSingletonInstance<T>(); }
catch (InvalidOperationException) { /* ABP startup not yet run — initialize the application first */ } Prevention
- Always create the ABP application before reading singletons from the service collection.
- Prefer GetSingletonInstanceOrNull + null check at uncertain call sites.
- Move reads that need the built provider into OnApplicationInitialization.
When it happens
Trigger: Calling services.GetSingletonInstance<T>() during the registration phase before the expected singleton was added — e.g. GetTypeFinder() before ITypeFinder is registered, or GetRequiredService(services) before IAbpApplication is added to the collection.
Common situations: Invoking ABP convenience extensions at the wrong lifecycle stage; a module's ConfigureServices not having run yet; manually building a partial IServiceCollection that omits a required ABP singleton; ordering bug where a dependent extension is called before AbpApplicationCreation adds its singletons.
Related errors
- Could not find {typeof(IServiceProviderFactory<TContainerBui
- Could not find an implementation of {typeof(IConfiguration).
- An object accessor is registered before for type: {typeof(T)
- Could not find an object of {typeof(T).AssemblyQualifiedName
- An error occurred during the initialize {contributor.GetType
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/2ee75ab5aa498797.
Report an issue: GitHub.