stride3d/stride · error · InvalidOperationException

IGraphicsDeviceFactory is not registered as a service

Error message

IGraphicsDeviceFactory is not registered as a service

What it means

GraphicsDeviceManager's constructor resolves the IGraphicsDeviceFactory from the game's service registry and throws when it is absent. The factory is what actually builds the platform GraphicsDevice, so without it the manager cannot function; Stride registers it in its normal platform bootstrap, so this failure indicates the service registry was not populated.

Solutions

  1. Use the standard platform Game entry point (e.g. MyGameMain with the platform bootstrap) so IGraphicsDeviceFactory is registered before GraphicsDeviceManager is created.
  2. Register a factory in game.Services before constructing the manager: game.Services.AddService<IGraphicsDeviceFactory>(new DeviceFactorySDL()); (platform-appropriate implementation).
  3. Don't construct GraphicsDeviceManager manually in tests/headless code; mock at a higher level or run the normal initialization path.

Example fix

// before
var game = new Game();
var gdm = new GraphicsDeviceManager(game); // factory missing
// after
var game = new Game();
game.Services.AddService<IGraphicsDeviceFactory>(new DeviceFactorySDL());
var gdm = new GraphicsDeviceManager(game);
Defensive patterns

Strategy: validation

Validate before calling

if (game.Services.GetService<IGraphicsDeviceFactory>() is null)
    game.Services.AddService<IGraphicsDeviceFactory>(new DeviceFactorySDL());
var gdm = new GraphicsDeviceManager(game);

Type guard

bool FactoryRegistered(Game g) => g.Services.GetService<IGraphicsDeviceFactory>() != null;

Try / catch

try { var gdm = new GraphicsDeviceManager(game); }
catch (InvalidOperationException ex) when (ex.Message.Contains("IGraphicsDeviceFactory"))
{
    game.Services.AddService<IGraphicsDeviceFactory>(new DeviceFactorySDL());
    gdm = new GraphicsDeviceManager(game);
}

Prevention

When it happens

Trigger: new GraphicsDeviceManager(game) where game.Services does not contain an IGraphicsDeviceFactory registration — typically when GraphicsDeviceManager is constructed before the platform bootstrap registers services, or with a custom Game subclass that bypasses the standard setup.

Common situations: Custom Game classes that never call the platform registration code, headless/unit-test harnesses instantiating GraphicsDeviceManager, constructing the manager too early in a custom Main, or a stripped/custom service registry.

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


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/abbb3c1c59a53d7b. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Games/GraphicsDeviceManager.cs:110

        /// <summary>
        ///   Initializes a new instance of the <see cref="GraphicsDeviceManager"/> class.
        /// </summary>
        /// <param name="game">The Game that needs to manage the Graphics Device.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="game"/> cannot be <see langword="null"/>.</exception>
        /// <exception cref="InvalidOperationException">
        ///   Could not get the required <see cref="IGraphicsDeviceFactory"/> service from the <paramref name="game"/>'s services.
        /// </exception>
        internal GraphicsDeviceManager(GameBase game)
        {
            ArgumentNullException.ThrowIfNull(game);

            this.game = game;

            lockDeviceCreation = new object();

            graphicsDeviceFactory = game.Services.GetService<IGraphicsDeviceFactory>()
                ?? throw new InvalidOperationException("IGraphicsDeviceFactory is not registered as a service");

            game.WindowCreated += GameOnWindowCreated;
        }


        /// <summary>
        ///   Occurs when a new Graphics Device is successfully created.
        /// </summary>
        public event EventHandler<EventArgs> DeviceCreated;
        /// <summary>
        ///   Occurs when the Graphics Device is being disposed.
        /// </summary>
        public event EventHandler<EventArgs> DeviceDisposing;

        /// <summary>
        ///   Occurs when the Graphics Device is being reset.
        /// </summary>
        public event EventHandler<EventArgs> DeviceReset;

View on GitHub (pinned to 96fad776d2)