{"record":{"id":"04e2c74e8f6f9e90","repo":"SignalR/SignalR","slug":"multiple-activators-for-type-0-are-registered-p","errorCode":null,"errorMessage":"Multiple activators for type {0} are registered. Please call GetServices instead.","messagePattern":"Multiple activators for type (.+?) are registered\\. Please call GetServices instead\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AspNet.SignalR.Core/DefaultDependencyResolver.cs","lineNumber":128,"sourceCode":"        }\n\n        public virtual object GetService(Type serviceType)\n        {\n            if (serviceType == null)\n            {\n                throw new ArgumentNullException(\"serviceType\");\n            }\n\n            IList<Func<object>> activators;\n            if (_resolvers.TryGetValue(serviceType, out activators))\n            {\n                if (activators.Count == 0)\n                {\n                    return null;\n                }\n                if (activators.Count > 1)\n                {\n                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_MultipleActivatorsAreaRegisteredCallGetServices, serviceType.FullName));\n                }\n                return Track(activators[0]);\n            }\n            return null;\n        }\n\n        public virtual IEnumerable<object> GetServices(Type serviceType)\n        {\n            IList<Func<object>> activators;\n            if (_resolvers.TryGetValue(serviceType, out activators))\n            {\n                if (activators.Count == 0)\n                {\n                    return null;\n                }\n                return activators.Select(Track).ToList();\n            }\n            return null;","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/SignalR/SignalR/blob/693053b89a9e1f5ce819e3233ed159a6409de22b/src/Microsoft.AspNet.SignalR.Core/DefaultDependencyResolver.cs#L110-L146","documentation":"Thrown by DefaultDependencyResolver.GetService when more than one activator is registered for the requested Type. GetService is single-instance and ambiguous when multiple registrations exist; the resolver refuses to silently pick one and directs the caller to GetServices (plural) instead.","triggerScenarios":"Registering two or more factories for the same Type via Register, then calling GetService on that Type.","commonSituations":"Multiple modules/libraries each register the same service type (e.g., several IHubPipeline modules registered as the pipeline), or a plugin composition that double-registers.","solutions":["Use GetServices(serviceType) to retrieve all registered instances when multiples are expected.","If a single instance is required, deregister duplicates so only one activator remains.","Audit Register calls (including third-party HostStartup classes) for the conflicting type."],"exampleFix":"// before\nvar single = resolver.GetService(typeof(IMyService));\n\n// after\nvar all = resolver.GetServices(typeof(IMyService));\nvar single = all.FirstOrDefault();","handlingStrategy":"validation","validationCode":"var all = resolver.GetServices(serviceType).ToList();\nvar single = all.Count == 1 ? all[0] : all.FirstOrDefault();","typeGuard":"var services = resolver.GetServices(serviceType)?.ToList() ?? new List<object>();\nobject single = services.Count > 1 ? null : services.FirstOrDefault();","tryCatchPattern":"try\n{\n    return resolver.GetService(serviceType);\n}\ncatch (InvalidOperationException)\n{\n    // multiple registrations; fall back to plural resolution\n    return resolver.GetServices(serviceType).FirstOrDefault();\n}","preventionTips":["Use GetServices (plural) when multiple registrations are expected.","Audit Register calls including third-party HostStartup modules for duplicate types.","Write a composition-root test that asserts at most one activator per single-instance service."],"tags":["invalidoperation","dependency-resolver","di","registration","server"],"backgroundTag":null,"analyzedSha":"693053b89a9e1f5ce819e3233ed159a6409de22b","analyzedAt":"2026-08-13T22:23:59.793Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}