stride3d/stride · error · InvalidOperationException
No service matches the given type.
Error message
No service matches the given type.
What it means
Thrown by ViewModelServiceProvider.Get (and Get<T>) when no registered service — in this provider or its parent provider — is an instance of the requested serviceType. Unlike TryGet, which returns null, Get guarantees a service, so the missing registration surfaces as an InvalidOperationException. This fires when editor code requests a service that was never registered (or was already unregistered).
Solutions
- Register the service before calling Get, or use TryGet and handle null
- Verify the requested Type matches the registered service's assignability
- Ensure the lookup happens after provider initialization (e.g. not during field initializers)
Example fix
// before var svc = provider.Get(typeof(IMyService)); // throws if not registered // after provider.RegisterService(new MyServiceImpl()); var svc = provider.Get(typeof(IMyService));
Defensive patterns
Strategy: fallback
Validate before calling
if (provider.TryGet(serviceType) == null)
throw new InvalidOperationException($"Service {serviceType.Name} must be registered before use"); Try / catch
try { svc = provider.Get(typeof(IMyService)); }
catch (InvalidOperationException ex) { log.Warn(ex, "Missing service"); svc = CreateDefault(); } Prevention
- Use TryGet + null handling for optional services
- Register all required services before any consumer runs
- Write an initialization test that resolves every required service type
When it happens
Trigger: Calling Get(Type) for a type never registered, after the service was removed, or on a provider whose parent chain also lacks the service.
Common situations: Typos in the requested type; services registered in a different provider instance; lookups happening before registration completes (e.g. in the view model constructor).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- No service matches the given type.
- A service of the same type has already been registered.
- Multiple services match the given type.
- The provided path is not a valid path name.
- Build manifest [ ] doesn't exist
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/eee53f114694e1b7.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation/ViewModels/ViewModelServiceProvider.cs:102
throw new InvalidOperationException("Multiple services match the given type.");
serviceFound = service;
}
return serviceFound ?? parentProvider?.TryGet(serviceType);
}
/// <inheritdoc/>
public T? TryGet<T>() where T : class
{
return TryGet(typeof(T)) as T;
}
/// <inheritdoc/>
public object Get(Type serviceType)
{
var result = TryGet(serviceType);
return result ?? throw new InvalidOperationException("No service matches the given type.");
}
/// <inheritdoc/>
public T Get<T>() where T : class
{
return TryGet<T>() ?? throw new InvalidOperationException("No service matches the given type.");
}
}
View on GitHub (pinned to 96fad776d2)