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

  1. Add the missing registration (RegisterSingleton/RegisterTransient/RegisterScoped/RegisterProvider) for serviceType.
  2. Verify the module's AddServices/registration call runs before any Get/GetViewModel resolution.
  3. Resolve from the correct ServiceManager instance for that service's hierarchy.
  4. 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

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


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)