stride3d/stride · error · ArgumentNullException

ObjectFactory can not be null

Error message

ObjectFactory can not be null

What it means

Null-assignment guard on SerializerSettings.ObjectFactory (context: the adjacent ObjectSerializerBackend property uses this pattern): assigning null would leave the serializer without a way to instantiate objects, so the setter rejects a null value. The faulting input is the value assigned to the property.

Solutions

  1. Assign a valid IObjectFactory (e.g. DefaultObjectFactory or your custom implementation)
  2. Correct the container registration so the factory resolves to a non-null instance

Example fix

// before
settings.ObjectFactory = null;
// after
settings.ObjectFactory = new DefaultObjectFactory(serviceRegistry);
Defensive patterns

Strategy: validation

Validate before calling

settings.ObjectFactory = factory ?? new DefaultObjectFactory();

Try / catch

try { settings.ObjectFactory = factory; } catch (ArgumentNullException) { settings.ObjectFactory = new DefaultObjectFactory(); }

Prevention

When it happens

Trigger: `settings.ObjectFactory = null`, or passing a result of an unregistered container resolve that returns null.

Common situations: Custom object factories wired through a DI container that was not fully built; settings copied between test and production code.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Serialization/SerializerSettings.cs:305

            {
                if (value == null)
                    throw new ArgumentNullException("value", $"{nameof(ObjectSerializerBackend)} can not be null");
                objectSerializerBackend = value;
            }
        }

        /// <summary>
        /// Gets or sets the default factory to instantiate a type. Default is <see cref="DefaultObjectFactory" />.
        /// </summary>
        /// <value>The default factory to instantiate a type.</value>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public IObjectFactory ObjectFactory
        {
            get { return objectFactory; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value", $"{nameof(ObjectFactory)} can not be null");
                objectFactory = value;
            }
        }

        /// <summary>
        /// Gets or sets the schema. Default is <see cref="CoreSchema" />.
        /// method.
        /// </summary>
        /// <value>The schema.</value>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public IYamlSchema Schema { get { return schema; } }

        public ISerializerFactorySelector SerializerFactorySelector { get; set; }

        /// <summary>
        /// Gets a methods that will build the proper chain of serializers out of the default chain.
        /// </summary>
        public Action<ChainedSerializer> ChainedSerializerFactory { get; set; }

View on GitHub (pinned to 96fad776d2)