{"record":{"id":"eee53f114694e1b7","repo":"stride3d/stride","slug":"no-service-matches-the-given-type-viewmodelserviceprovider","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/ViewModelServiceProvider.cs","lineNumber":102,"sourceCode":"                throw new InvalidOperationException(\"Multiple services match the given type.\");\n\n            serviceFound = service;\n        }\n\n        return serviceFound ?? parentProvider?.TryGet(serviceType);\n    }\n\n    /// <inheritdoc/>\n    public T? TryGet<T>() where T : class\n    {\n        return TryGet(typeof(T)) as T;\n    }\n\n    /// <inheritdoc/>\n    public object Get(Type serviceType)\n    {\n        var result = TryGet(serviceType);\n        return result ?? throw new InvalidOperationException(\"No service matches the given type.\");\n    }\n\n    /// <inheritdoc/>\n    public T Get<T>() where T : class\n    {\n        return TryGet<T>() ?? throw new InvalidOperationException(\"No service matches the given type.\");\n    }\n}\n","sourceCodeStart":84,"sourceCodeEnd":111,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation/ViewModels/ViewModelServiceProvider.cs#L84-L111","documentation":"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).","triggerScenarios":"Calling Get(Type) for a type never registered, after the service was removed, or on a provider whose parent chain also lacks the service.","commonSituations":"Typos in the requested type; services registered in a different provider instance; lookups happening before registration completes (e.g. in the view model constructor).","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)"],"exampleFix":"// before\nvar svc = provider.Get(typeof(IMyService)); // throws if not registered\n// after\nprovider.RegisterService(new MyServiceImpl());\nvar svc = provider.Get(typeof(IMyService));","handlingStrategy":"fallback","validationCode":"if (provider.TryGet(serviceType) == null)\n    throw new InvalidOperationException($\"Service {serviceType.Name} must be registered before use\");","typeGuard":null,"tryCatchPattern":"try { svc = provider.Get(typeof(IMyService)); }\ncatch (InvalidOperationException ex) { log.Warn(ex, \"Missing service\"); svc = CreateDefault(); }","preventionTips":["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"],"tags":["dotnet","dependency-injection","missing-service"],"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"}