stride3d/stride · critical · InvalidOperationException
Unable to create a IGraphicsDeviceService
Error message
Unable to create a IGraphicsDeviceService
What it means
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.
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
Example fix
// before var game = new GameBase(); // after var game = new MyGame(); // constructor: new GraphicsDeviceManager(this);
Defensive patterns
Strategy: validation
Validate before calling
if (services.GetService<IGraphicsDeviceService>() == null) throw new InvalidOperationException("Register IGraphicsDeviceService before constructing Game"); Try / catch
try { var game = new MyGame(); } catch (InvalidOperationException ex) when (ex.Message.Contains("IGraphicsDeviceService")) { /* provide graphics service */ } Prevention
- 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
When it happens
Trigger: Constructing a Game whose Services do not contain an IGraphicsDeviceService, e.g. using a raw GameBase without a GraphicsDeviceManager/GraphicsDeviceService registered first.
Common situations: 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.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- adapter
- No GraphicsDeviceManager found
- Unable to find a GraphicsDevice instance
- A overlaps with another element. Check the element's offset
- A region can only be specified for Textures with…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/adf8f1073d4b6008.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Games/GameBase.cs:961
IsActive = false;
OnDeactivated(this, EventArgs.Empty);
}
}
private void GamePlatform_Exiting(object sender, EventArgs e)
{
OnExiting(this, EventArgs.Empty);
}
private void SetupGraphicsDeviceEvents()
{
// Find the IGraphicsDeviceSerive.
graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();
// If there is no graphics device service, don't go further as the whole Game would not work
if (graphicsDeviceService == null)
{
throw new InvalidOperationException("Unable to create a IGraphicsDeviceService");
}
if (graphicsDeviceService.GraphicsDevice == null)
{
throw new InvalidOperationException("Unable to find a GraphicsDevice instance");
}
resumeManager = new ResumeManager(Services);
GraphicsDevice = graphicsDeviceService.GraphicsDevice;
graphicsDeviceService.DeviceCreated += GraphicsDeviceService_DeviceCreated;
graphicsDeviceService.DeviceResetting += GraphicsDeviceService_DeviceResetting;
graphicsDeviceService.DeviceReset += GraphicsDeviceService_DeviceReset;
graphicsDeviceService.DeviceDisposing += GraphicsDeviceService_DeviceDisposing;
}
private void DisposeGraphicsDeviceEvents()
{View on GitHub (pinned to 96fad776d2)