{"record":{"id":"4444ff05cbc4f732","repo":"stride3d/stride","slug":"unable-to-find-a-graphicsdevice-instance","errorCode":null,"errorMessage":"Unable to find a GraphicsDevice instance","messagePattern":"Unable to find a GraphicsDevice instance","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"sources/engine/Stride.Games/GameBase.cs","lineNumber":966,"sourceCode":"        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        {\n            if (graphicsDeviceService != null)\n            {\n                graphicsDeviceService.DeviceCreated -= GraphicsDeviceService_DeviceCreated;\n                graphicsDeviceService.DeviceResetting -= GraphicsDeviceService_DeviceResetting;\n                graphicsDeviceService.DeviceReset -= GraphicsDeviceService_DeviceReset;","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Games/GameBase.cs#L948-L984","documentation":"After locating IGraphicsDeviceService in the GameBase constructor, it checks that the service actually exposes a non-null GraphicsDevice. A registered service with a null device means no real rendering device was created, so the constructor throws this InvalidOperationException.","triggerScenarios":"A custom or stub IGraphicsDeviceService registered in Services whose GraphicsDevice property is null; device creation failing silently before Game construction; uninitialized custom device implementations.","commonSituations":"Test doubles returning null GraphicsDevice; custom device factories failing on machines without supported GPU/drivers; creating the service before the device is created.","solutions":["Ensure the IGraphicsDeviceService creates/returns a valid GraphicsDevice before the Game constructor runs","Verify GPU drivers and that the platform supports device creation","In tests, mock a non-null GraphicsDevice or use Stride's headless abstractions"],"exampleFix":"// before\npublic class FakeService : IGraphicsDeviceService { public GraphicsDevice GraphicsDevice => null; }\n// after\npublic class FakeService : IGraphicsDeviceService { public GraphicsDevice GraphicsDevice { get; } = CreateMockDevice(); }","handlingStrategy":"validation","validationCode":"if (services.GetService<IGraphicsDeviceService>()?.GraphicsDevice == null) throw new InvalidOperationException(\"GraphicsDevice not ready\");","typeGuard":"bool HasDevice(IGraphicsDeviceService s) => s?.GraphicsDevice != null;","tryCatchPattern":"try { var game = new MyGame(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"GraphicsDevice instance\")) { /* fix device creation, then retry */ }","preventionTips":["Ensure device creation completes before Game construction","Validate GPU drivers/environment on target machines","Never register stub services with null devices outside tests"],"tags":["graphics","device","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"}