{"record":{"id":"0ea5067370452da1","repo":"stride3d/stride","slug":"no-service-matches-the-given-type","errorCode":null,"errorMessage":"No service matches the given type.","messagePattern":"No service matches the given type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation/ViewModels/NullServiceProvider.cs","lineNumber":48,"sourceCode":"        throw new InvalidOperationException(\"Cannot unregister a service on a NullServiceProvider.\");\n    }\n\n    /// <inheritdoc/>\n    public object? TryGet(Type serviceType)\n    {\n        return null;\n    }\n\n    /// <inheritdoc/>\n    public T? TryGet<T>() where T : class\n    {\n        return null;\n    }\n\n    /// <inheritdoc/>\n    public object Get(Type serviceType)\n    {\n        throw new InvalidOperationException(\"No service matches the given type.\");\n    }\n\n    /// <inheritdoc/>\n    public T Get<T>() where T : class\n    {\n        throw new InvalidOperationException(\"No service matches the given type.\");\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":57,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation/ViewModels/NullServiceProvider.cs#L30-L57","documentation":"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.","triggerScenarios":"Calling NullServiceProvider.Get(Type) or Get<T>() — any lookup at all, since the provider never resolves anything.","commonSituations":"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.","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"],"exampleFix":"// before\nvar dialogService = viewModel.ServiceProvider.Get<IDialogService>();\n// after\nif (viewModel.ServiceProvider is NullServiceProvider) throw new InvalidOperationException(\"ViewModel has no service provider\");\nvar dialogService = viewModel.ServiceProvider.Get<IDialogService>();","handlingStrategy":"fallback","validationCode":"if (serviceProvider is Stride.Core.Presentation.ViewModels.NullServiceProvider)\n    throw new InvalidOperationException(\"No real service provider configured for this view model\");","typeGuard":"bool HasRealProvider(IServiceProvider p) => p is not NullServiceProvider;","tryCatchPattern":"try { svc = provider.Get(typeof(IMyService)); }\ncatch (InvalidOperationException ex) { log.Warn(ex, \"Service lookup on null provider\"); svc = null; }","preventionTips":["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"],"tags":["dotnet","dependency-injection","service-provider"],"backgroundTag":"resource-not-found","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}