{"record":{"id":"93a394d604822dd2","repo":"LykosAI/StabilityMatrix","slug":"service-of-type-servicetype-is-not-registered-for-typeof-t","errorCode":null,"errorMessage":"Service of type {serviceType} is not registered for {typeof(T)}","messagePattern":"Service of type (.+?) is not registered for (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Services/ServiceManager.cs","lineNumber":201,"sourceCode":"            }\n            return (T)instance;\n        }\n\n        if (providers.TryGetValue(serviceType, out var provider))\n        {\n            if (provider is null)\n            {\n                throw new ArgumentException($\"Service of type {serviceType} was registered as null\");\n            }\n            var result = provider();\n            if (result is null)\n            {\n                throw new ArgumentException($\"Service provider for type {serviceType} returned null\");\n            }\n            return (T)result;\n        }\n\n        throw new ArgumentException($\"Service of type {serviceType} is not registered for {typeof(T)}\");\n    }\n\n    /// <summary>\n    /// Get a view model instance\n    /// </summary>\n    [SuppressMessage(\"ReSharper\", \"InconsistentlySynchronizedField\")]\n    public TService Get<TService>()\n        where TService : T\n    {\n        if (instances.TryGetValue(typeof(TService), out var instance))\n        {\n            if (instance is null)\n            {\n                throw new ArgumentException($\"Service of type {typeof(TService)} was registered as null\");\n            }\n            return (TService)instance;\n        }\n","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Services/ServiceManager.cs#L183-L219","documentation":"ServiceManager.Get exhausted instances and providers without finding serviceType, so it reports that the service is not registered for the manager's type T. This is the container's 'unknown service' error, thrown as ArgumentException.","triggerScenarios":"Calling Get(serviceType) for a type never registered in this ServiceManager instance, after a registration step was skipped or failed, or on the wrong ServiceManager<T> instance (e.g. asking the ViewModel manager for a plain service).","commonSituations":"Startup DI registration silently failing before resolution; an AddServices method for the module never called; resolving a plugin-provided service without the plugin loaded; typos in string/Type-based lookups.","solutions":["Add the missing registration (RegisterSingleton/RegisterTransient/RegisterScoped/RegisterProvider) for serviceType.","Verify the module's AddServices/registration call runs before any Get/GetViewModel resolution.","Resolve from the correct ServiceManager instance for that service's hierarchy.","Use the generic Get<T>() with a compile-time check and confirm registration order in App startup."],"exampleFix":"// before\nvar updater = serviceManager.Get<IUpdateChecker>(); // never registered\n// after\n// in AddServices:\nmanager.RegisterSingleton<IUpdateChecker, UpdateChecker>();\nvar updater = manager.Get<IUpdateChecker>();","handlingStrategy":"try-catch","validationCode":"if (!manager.HasService<TService>()) { ShowStartupDiagnostics(); return; }","typeGuard":null,"tryCatchPattern":"try { var svc = manager.Get<TService>(); }\ncatch (ArgumentException ex) { logger.Fatal(ex, \"Service {Type} missing — DI registration incomplete\"); throw; }","preventionTips":["Call every module's AddServices before any resolution in App startup.","Smoke-test the container at startup by resolving all required services once.","Resolve via generic Get<T>() and keep registrations next to consumption documentation."],"tags":["dependency-injection","missing-registration","csharp"],"backgroundTag":"record-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}