stride3d/stride · error · InvalidOperationException
No service matches the given type.
Error message
No service matches the given type.
What it means
NullServiceProvider is a deliberately inert IServiceProvider whose Get methods always throw. It is used as a placeholder service provider (e.g. for view models with no services) so any service lookup on it is by definition a bug.
Solutions
- Do not look up services from NullServiceProvider; inject a real ViewModelServiceProvider instead
- Check where the view model got its ServiceProvider and ensure the real provider is passed in before services are consumed
- If NullServiceProvider is intentionally used, remove the Get call or null-check the provider before resolving
Example fix
// before
var dialogService = viewModel.ServiceProvider.Get<IDialogService>();
// after
if (viewModel.ServiceProvider is NullServiceProvider) throw new InvalidOperationException("ViewModel has no service provider");
var dialogService = viewModel.ServiceProvider.Get<IDialogService>(); Defensive patterns
Strategy: fallback
Validate before calling
if (serviceProvider is Stride.Core.Presentation.ViewModels.NullServiceProvider)
throw new InvalidOperationException("No real service provider configured for this view model"); Type guard
bool HasRealProvider(IServiceProvider p) => p is not NullServiceProvider;
Try / catch
try { svc = provider.Get(typeof(IMyService)); }
catch (InvalidOperationException ex) { log.Warn(ex, "Service lookup on null provider"); svc = null; } Prevention
- Never pass NullServiceProvider to production view models; use ViewModelServiceProvider
- Track provider lifetime in one place so lookups happen only after real providers are wired
- Treat NullServiceProvider as a design-time/test-only stub
When it happens
Trigger: Calling NullServiceProvider.Get(Type) or Get<T>() — any lookup at all, since the provider never resolves anything.
Common situations: A view model was constructed with or defaulted to NullServiceProvider and application code (or a template/property binding) asks it for a service such as a dialog service or logger.
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
- The given IViewModelServiceProvider instance does not…
- A service of the same type has already been registered.
- Multiple services match the given type.
- No service matches the given type.
- The provided path is not a valid path name.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/0ea5067370452da1.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation/ViewModels/NullServiceProvider.cs:48
throw new InvalidOperationException("Cannot unregister a service on a NullServiceProvider.");
}
/// <inheritdoc/>
public object? TryGet(Type serviceType)
{
return null;
}
/// <inheritdoc/>
public T? TryGet<T>() where T : class
{
return null;
}
/// <inheritdoc/>
public object Get(Type serviceType)
{
throw new InvalidOperationException("No service matches the given type.");
}
/// <inheritdoc/>
public T Get<T>() where T : class
{
throw new InvalidOperationException("No service matches the given type.");
}
}
View on GitHub (pinned to 96fad776d2)