stride3d/stride · error · InvalidOperationException

Requested type and current platform are incompatible.

Error message

Requested type and current platform are incompatible.

What it means

GameContextFactory.NewGameContext tries to build a GameContext matching the requested GameContextType (windowed, offscreen, headless, etc.) for the current platform. If no context implementation matches, res stays null and this InvalidOperationException is thrown, meaning the requested context type has no implementation on the running platform.

Solutions

  1. Request a supported GameContextType for the platform (e.g. Headless on servers)
  2. Add platform detection and select the context type conditionally before calling Run
  3. If targeting a custom platform, implement and register the corresponding GameContext factory branch

Example fix

// before
var ctx = GameContextFactory.NewGameContext(GameContextType.Window);
// after
var ctx = GameContextFactory.NewGameContext(Environment.UserInteractive ? GameContextType.Window : GameContextType.Headless);
Defensive patterns

Strategy: validation

Validate before calling

var type = Environment.UserInteractive ? GameContextType.Window : GameContextType.Headless;
var ctx = GameContextFactory.NewGameContext(type);

Try / catch

try { ctx = GameContextFactory.NewGameContext(requested); } catch (InvalidOperationException ex) when (ex.Message.Contains("platform are incompatible")) { ctx = GameContextFactory.NewGameContext(GameContextType.Headless); }

Prevention

When it happens

Trigger: Requesting AppContextType.Window (or a type with no implementation) on a platform where that context type is unsupported, e.g. requesting a windowed context on a headless/unsupported platform; passing an invalid/unmapped GameContextType.

Common situations: Running a windowed game on a server/CI machine without window support; custom platform targets lacking a context implementation; misconfigured game settings choosing an unavailable context type.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Games/GameContextFactory.cs:70

                    res = NewGameContextWpf(requestedWidth, requestedHeight, isUserManagingRun);
                    break;
                case AppContextType.UWPXaml:
                    res = NewGameContextUWPXaml(requestedWidth, requestedHeight);
                    break;
                case AppContextType.UWPCoreWindow:
                    res = NewGameContextUWPCoreWindow(requestedWidth, requestedHeight);
                    break;
                case AppContextType.iOS:
                    res = NewGameContextiOS();
                    break;
                case AppContextType.Headless:
                    res = new GameContextHeadless(requestedWidth, requestedHeight);
                    break;
            }

            if (res == null)
            {
                throw new InvalidOperationException("Requested type and current platform are incompatible.");
            }

            return res;
        }

        public static GameContext NewGameContextiOS()
        {
#if STRIDE_PLATFORM_IOS
            return new GameContextiOS(null);
#else
            return null;
#endif
        }

        public static GameContext NewGameContextAndroid()
        {
#if STRIDE_PLATFORM_ANDROID
            return new GameContextAndroid(null, null);

View on GitHub (pinned to 96fad776d2)