{"record":{"id":"bb681e46b961faae","repo":"stride3d/stride","slug":"no-graphicsdeviceservice-found","errorCode":null,"errorMessage":"No GraphicsDeviceService found","messagePattern":"No GraphicsDeviceService found","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"sources/engine/Stride.Games/GameBase.cs","lineNumber":365,"sourceCode":"        }\n\n        internal void InitializeBeforeRun()\n        {\n            try\n            {\n                using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize))\n                {\n                    // Initialize this instance and all game systems before trying to create the device.\n                    Initialize();\n\n                    // Make sure that the device is already created\n                    graphicsDeviceManager.CreateDevice();\n\n                    // Gets the graphics device service\n                    graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();\n                    if (graphicsDeviceService == null)\n                    {\n                        throw new InvalidOperationException(\"No GraphicsDeviceService found\");\n                    }\n\n                    // Checks the graphics device\n                    if (graphicsDeviceService.GraphicsDevice == null)\n                    {\n                        throw new InvalidOperationException(\"No GraphicsDevice found\");\n                    }\n\n                    // Setup the graphics device if it was not already setup.\n                    SetupGraphicsDeviceEvents();\n\n                    // Drain pending GPU work before the window is destroyed: a queued flip-model\n                    // Present can only complete while its window is alive, and the device is\n                    // destroyed after the window on the exit path.\n                    Window.Closing += (_, _) => GraphicsDevice?.WaitForGpuIdle();\n\n                    // Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc\n                    BeginDraw();","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Games/GameBase.cs#L347-L383","documentation":"GameBase.InitializeBeforeRun, after creating the graphics device via the GraphicsDeviceManager, resolves IGraphicsDeviceService from the service registry; if absent it throws InvalidOperationException because the rest of game initialization depends on that service. It indicates the device was created but its service was never registered in Services.","triggerScenarios":"Running a custom GameBase subclass whose Services registry lacks IGraphicsDeviceService (e.g. graphicsDeviceManager not used as intended or service registration removed/skipped).","commonSituations":"Replacing GraphicsDeviceManager with custom device code without registering the service; manually clearing the Services registry; engine version changes in service registration order.","solutions":["Ensure GraphicsDeviceManager.CreateDevice() runs during initialization and registers IGraphicsDeviceService in Services","Add the service manually: Services.AddService<IGraphicsDeviceService>(graphicsDeviceService)","Verify you are not overriding InitializeBeforeRun in a way that bypasses base device setup"],"exampleFix":"// before\nServices.RemoveService<IGraphicsDeviceService>(); // or custom device path that never registers it\n// after\ngraphicsDeviceManager.CreateDevice();\nServices.AddService<IGraphicsDeviceService>(graphicsDeviceService);","handlingStrategy":"try-catch","validationCode":"if (Services.GetService<IGraphicsDeviceService>() is null)\n    throw new InvalidOperationException(\"Register IGraphicsDeviceService before initializing the game\");","typeGuard":"bool HasDeviceService(IServiceRegistry services) => services.GetService<IGraphicsDeviceService>() is not null;","tryCatchPattern":"try { game.InitializeBeforeRun(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"GraphicsDeviceService\")) { /* log missing service and abort */ }","preventionTips":["Always go through GraphicsDeviceManager for device creation","Never clear Services registrations added during initialization"],"tags":["game","graphics-device","missing-service"],"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"}