stride3d/stride · error · ArgumentNullException

registry

Error message

registry

What it means

The protected EntityManager(IServiceRegistry) constructor throws ArgumentNullException when the registry argument is null, because the manager stores it as Services and needs it to resolve processors and other systems. It is raised before any entity bookkeeping is set up.

Solutions

  1. Pass a valid IServiceRegistry instance (e.g. the game's Services property)
  2. Register IServiceRegistry in your DI container before constructing EntityManager
  3. Add a null guard at the call site so construction is skipped until services exist

Example fix

// before
var entityManager = new MyEntityManager(null);
// after
var entityManager = new MyEntityManager(game.Services);
Defensive patterns

Strategy: try-catch

Validate before calling

if (registry == null) throw new InvalidOperationException("IServiceRegistry must be resolved before creating EntityManager");

Type guard

static bool HasRegistry(IServiceRegistry r) => r != null;

Try / catch

try { var em = new MyEntityManager(registry); }
catch (ArgumentNullException ex) when (ex.ParamName == "registry") { /* resolve services first */ }

Prevention

When it happens

Trigger: Calling the constructor (from a derived class or via DI) passing null for the IServiceRegistry parameter.

Common situations: Manual instantiation of EntityManager in unit tests or custom game setups without a configured service registry; DI container missing a registration for IServiceRegistry.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Engine/Engine/EntityManager.cs:83

        /// <summary>
        /// Occurs when a new component type is added.
        /// </summary>
        public event EventHandler<TypeInfo> ComponentTypeAdded;

        /// <summary>
        /// Occurs when a component changed for an entity (Added or removed)
        /// </summary>
        public event EventHandler<EntityComponentEventArgs> ComponentChanged;

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityManager"/> class.
        /// </summary>
        /// <param name="registry">The registry.</param>
        /// <exception cref="System.ArgumentNullException">registry</exception>
        protected EntityManager(IServiceRegistry registry)
        {
            if (registry == null) throw new ArgumentNullException("registry");
            Services = registry;

            entities = new HashSet<Entity>();
            processors = new TrackingEntityProcessorCollection(this);
            pendingProcessors = new EntityProcessorCollection();

            componentTypes = new HashSet<TypeInfo>();
            MapComponentTypeToProcessors = new Dictionary<TypeInfo, EntityProcessorCollectionPerComponentType>();

            currentDependentProcessors = new List<EntityProcessor>(10);

            flexibleProcessors = new ProcessorManager(registry);
        }

        /// <summary>
        /// Gets the services.
        /// </summary>
        /// <value>The services.</value>

View on GitHub (pinned to 96fad776d2)