LykosAI/StabilityMatrix · error · ArgumentException
Service of type is not registered for
Error message
Service of type {serviceType} is not registered for {typeof(T)} What it means
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.
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.
Example fix
// before var updater = serviceManager.Get<IUpdateChecker>(); // never registered // after // in AddServices: manager.RegisterSingleton<IUpdateChecker, UpdateChecker>(); var updater = manager.Get<IUpdateChecker>();
Defensive patterns
Strategy: try-catch
Validate before calling
if (!manager.HasService<TService>()) { ShowStartupDiagnostics(); return; } Try / catch
try { var svc = manager.Get<TService>(); }
catch (ArgumentException ex) { logger.Fatal(ex, "Service {Type} missing — DI registration incomplete"); throw; } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Service type is not assignable to
- Service type is not assignable to
- Scoped provider for returned null.
- Service of type is already registered for
- Service of type is already registered for
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/93a394d604822dd2.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/Services/ServiceManager.cs:201
}
return (T)instance;
}
if (providers.TryGetValue(serviceType, out var provider))
{
if (provider is null)
{
throw new ArgumentException($"Service of type {serviceType} was registered as null");
}
var result = provider();
if (result is null)
{
throw new ArgumentException($"Service provider for type {serviceType} returned null");
}
return (T)result;
}
throw new ArgumentException($"Service of type {serviceType} is not registered for {typeof(T)}");
}
/// <summary>
/// Get a view model instance
/// </summary>
[SuppressMessage("ReSharper", "InconsistentlySynchronizedField")]
public TService Get<TService>()
where TService : T
{
if (instances.TryGetValue(typeof(TService), out var instance))
{
if (instance is null)
{
throw new ArgumentException($"Service of type {typeof(TService)} was registered as null");
}
return (TService)instance;
}
View on GitHub (pinned to af93d6ef57)