{"record":{"id":"2ee75ab5aa498797","repo":"abpframework/abp","slug":"could-not-find-singleton-service-typeof-t-assem","errorCode":null,"errorMessage":"Could not find singleton service: {typeof(T).AssemblyQualifiedName}","messagePattern":"Could not find singleton service: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs","lineNumber":39,"sourceCode":"\n    public static ITypeFinder GetTypeFinder(this IServiceCollection services)\n    {\n        return services.GetSingletonInstance<ITypeFinder>();\n    }\n\n    public static T? GetSingletonInstanceOrNull<T>(this IServiceCollection services)\n    {\n        return (T?)services\n            .FirstOrDefault(d => d.ServiceType == typeof(T))\n            ?.NormalizedImplementationInstance();\n    }\n\n    public static T GetSingletonInstance<T>(this IServiceCollection services)\n    {\n        var service = services.GetSingletonInstanceOrNull<T>();\n        if (service == null)\n        {\n            throw new InvalidOperationException(\"Could not find singleton service: \" + typeof(T).AssemblyQualifiedName);\n        }\n\n        return service;\n    }\n\n    public static IServiceProvider BuildServiceProviderFromFactory([NotNull] this IServiceCollection services)\n    {\n        Check.NotNull(services, nameof(services));\n\n        foreach (var service in services)\n        {\n            var factoryInterface = service.NormalizedImplementationInstance()?.GetType()\n                .GetTypeInfo()\n                .GetInterfaces()\n                .FirstOrDefault(i => i.GetTypeInfo().IsGenericType &&\n                                     i.GetGenericTypeDefinition() == typeof(IServiceProviderFactory<>));\n\n            if (factoryInterface == null)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — called before ITypeFinder is registered\nvar finder = services.GetTypeFinder();\n\n// after — register/initialize the ABP application first, then access\nvar application = await AbpApplicationFactory.CreateAsync<YourModule>(services);\nvar finder = services.GetTypeFinder();","handlingStrategy":"validation","validationCode":"// Use the OrNull variant and branch on null rather than letting GetSingletonInstance throw\nvar finder = services.GetSingletonInstanceOrNull<ITypeFinder>();\nif (finder == null)\n    throw new InvalidOperationException(\"ABP not initialized: ensure AbpApplicationFactory.CreateAsync ran.\");","typeGuard":null,"tryCatchPattern":"try { var svc = services.GetSingletonInstance<T>(); }\ncatch (InvalidOperationException) { /* ABP startup not yet run — initialize the application first */ }","preventionTips":["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."],"tags":["dependency-injection","startup","lifecycle","abp-core"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}