stride3d/stride · error · InvalidOperationException

Already initialized.

Error message

Already initialized.

What it means

GameSystemCollection.Initialize throws this InvalidOperationException if called when State is anything other than None, i.e. the collection has already been initialized. This prevents double initialization of game systems.

Solutions

  1. Call Initialize() only once per collection instance, or create a new collection for a new lifecycle
  2. Check State == GameSystemState.None before calling Initialize
  3. Make init code idempotent at the call site (track your own initialized flag)

Example fix

// before
systems.Initialize();
systems.Initialize(); // throws
// after
if (systems.State == GameSystemState.None) systems.Initialize();
Defensive patterns

Strategy: validation

Validate before calling

if (systems.State == GameSystemState.None) systems.Initialize();

Try / catch

try { systems.Initialize(); } catch (InvalidOperationException ex) when (ex.Message == "Already initialized.") { /* already done, no-op */ }

Prevention

When it happens

Trigger: Calling Initialize() twice on the same GameSystemCollection; calling it on a collection that LoadContent already advanced past Initialized; shared collection initialized by both host code and Game.

Common situations: Re-initializing after a restart without recreating systems; both a custom host and the game engine initializing the same systems; accidental duplicate init calls in test setup.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Games/GameSystemCollection.cs:203

                foreach (var contentable in contentableGameSystems)
                {
                    currentlyContentGameSystems.Add(contentable);
                }
            }

            foreach (var contentable in currentlyContentGameSystems)
            {
                contentable.UnloadContent();
            }

            currentlyContentGameSystems.Clear();
        }

        public void Initialize()
        {
            if (State != GameSystemState.None)
            {
                throw new InvalidOperationException("Already initialized.");
            }

            State = GameSystemState.Initialized;

            InitializePendingGameSystems();
        }

        private void InitializePendingGameSystems()
        {
            // Add all game systems that were added to this game instance before the game started.
            while (pendingGameSystems.Count != 0)
            {
                var gameSystemName = GetGameSystemName(pendingGameSystems[0]);
                using (var profile = Profiler.Begin(GameProfilingKeys.GameSystemInitialize, gameSystemName))
                    pendingGameSystems[0].Initialize();
                if (State == GameSystemState.ContentLoaded && pendingGameSystems[0] is IContentable)
                {
                    var contentable = (IContentable)pendingGameSystems[0];

View on GitHub (pinned to 96fad776d2)