stride3d/stride · error · InvalidOperationException

Not initialized.

Error message

Not initialized.

What it means

GameSystemCollection.LoadContent requires the collection to be in the Initialized state; it throws this InvalidOperationException if content is loaded in any other state. This enforces the GameSystem lifecycle: Initialize -> LoadContent -> (Update/Draw).

Solutions

  1. Call Initialize() before LoadContent() and only once per lifecycle stage
  2. Check the State property before calling LoadContent
  3. Let GameBase drive the lifecycle automatically instead of calling methods manually

Example fix

// before
systems.LoadContent();
systems.Initialize();
// after
systems.Initialize();
systems.LoadContent();
Defensive patterns

Strategy: validation

Validate before calling

if (systems.State == GameSystemState.Initialized) systems.LoadContent();

Try / catch

try { systems.LoadContent(); } catch (InvalidOperationException ex) when (ex.Message == "Not initialized.") { systems.Initialize(); systems.LoadContent(); }

Prevention

When it happens

Trigger: Calling LoadContent() before Initialize(), after content was already unloaded (state back to Initialized handled elsewhere), or calling it twice without an UnloadContent in between where state already advanced past Initialized.

Common situations: Manually driving the game-system lifecycle out of order in tests or custom hosts; calling LoadContent in a constructor; forgetting Initialize before LoadContent in a custom loop.

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/c80c4920c5ef9950. Report an issue: GitHub.

Appendix: source

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

                        {
                            drawable.Key.Draw(gameTime);
                            drawable.Key.EndDraw();
                        }
                    }
                }
            }

            currentlyDrawingGameSystems.Clear();
        }

        /// <summary>
        /// Loads the content.
        /// </summary>
        public virtual void LoadContent()
        {
            if (State != GameSystemState.Initialized)
            {
                throw new InvalidOperationException("Not initialized.");
            }

            State = GameSystemState.ContentLoaded;

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

            foreach (var contentable in currentlyContentGameSystems)
            {
                using (var profile = Profiler.Begin(GameProfilingKeys.GameSystemLoadContent, GetGameSystemName(contentable)))
                    contentable.LoadContent();
            }

View on GitHub (pinned to 96fad776d2)