{"record":{"id":"adf8f1073d4b6008","repo":"stride3d/stride","slug":"unable-to-create-a-igraphicsdeviceservice","errorCode":null,"errorMessage":"Unable to create a IGraphicsDeviceService","messagePattern":"Unable to create a IGraphicsDeviceService","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"sources/engine/Stride.Games/GameBase.cs","lineNumber":961,"sourceCode":"                IsActive = false;\n                OnDeactivated(this, EventArgs.Empty);\n            }\n        }\n\n        private void GamePlatform_Exiting(object sender, EventArgs e)\n        {\n            OnExiting(this, EventArgs.Empty);\n        }\n\n        private void SetupGraphicsDeviceEvents()\n        {\n            // Find the IGraphicsDeviceSerive.\n            graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();\n\n            // If there is no graphics device service, don't go further as the whole Game would not work\n            if (graphicsDeviceService == null)\n            {\n                throw new InvalidOperationException(\"Unable to create a IGraphicsDeviceService\");\n            }\n\n            if (graphicsDeviceService.GraphicsDevice == null)\n            {\n                throw new InvalidOperationException(\"Unable to find a GraphicsDevice instance\");\n            }\n\n            resumeManager = new ResumeManager(Services);\n\n            GraphicsDevice = graphicsDeviceService.GraphicsDevice;\n            graphicsDeviceService.DeviceCreated += GraphicsDeviceService_DeviceCreated;\n            graphicsDeviceService.DeviceResetting += GraphicsDeviceService_DeviceResetting;\n            graphicsDeviceService.DeviceReset += GraphicsDeviceService_DeviceReset;\n            graphicsDeviceService.DeviceDisposing += GraphicsDeviceService_DeviceDisposing;\n        }\n\n        private void DisposeGraphicsDeviceEvents()\n        {","sourceCodeStart":943,"sourceCodeEnd":979,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Games/GameBase.cs#L943-L979","documentation":"In its constructor, GameBase looks up IGraphicsDeviceService in Services; this service provides the underlying GraphicsDevice. If no service is registered, the game cannot function and the constructor throws this InvalidOperationException.","triggerScenarios":"Constructing a Game whose Services do not contain an IGraphicsDeviceService, e.g. using a raw GameBase without a GraphicsDeviceManager/GraphicsDeviceService registered first.","commonSituations":"Using a minimal custom Game subclass without a GraphicsDeviceManager; unit-testing GameBase with an empty ServiceRegistry; building a custom hosting layer that forgot the graphics service.","solutions":["Register a GraphicsDeviceManager (which registers IGraphicsDeviceService) in the Game constructor before base initialization","Provide a mock/stub IGraphicsDeviceService in the Services registry for tests","Use a documented headless mode instead of bypassing the graphics service"],"exampleFix":"// before\nvar game = new GameBase();\n// after\nvar game = new MyGame(); // constructor: new GraphicsDeviceManager(this);","handlingStrategy":"validation","validationCode":"if (services.GetService<IGraphicsDeviceService>() == null) throw new InvalidOperationException(\"Register IGraphicsDeviceService before constructing Game\");","typeGuard":null,"tryCatchPattern":"try { var game = new MyGame(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"IGraphicsDeviceService\")) { /* provide graphics service */ }","preventionTips":["Register the graphics device service before Game construction","In tests, register a mock IGraphicsDeviceService in the ServiceRegistry","Use Game subclasses that set up graphics automatically"],"tags":["graphics","dependency-injection","constructor"],"backgroundTag":"missing-dependency","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}