JamesNK/Newtonsoft.Json · error · JsonSerializationException

No object created.

Error message

No object created.

What it means

Thrown by CustomCreationConverter<T>.ReadJson when the abstract Create(Type) override returns null. After calling Create to get the target object, the converter null-checks it; if no object is created it cannot populate and throws this JsonSerializationException.

Source

Thrown at Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs:70

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return null;
            }

            T value = Create(objectType);
            if (value == null)
            {
                throw new JsonSerializationException("No object created.");
            }

            serializer.Populate(reader, value);
            return value;
        }

        /// <summary>
        /// Creates an object which will then be populated by the serializer.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <returns>The created object.</returns>
        public abstract T Create(Type objectType);

        /// <summary>
        /// Determines whether this instance can convert the specified object type.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <returns>

View on GitHub (pinned to 4f73e74372)

Solutions

  1. Make Create(Type) always return a non-null instance; add a default branch that throws a descriptive exception or returns a concrete fallback.
  2. Check your DI/factory registration covers every objectType the deserializer can request.
  3. If null is legitimately possible, switch from CustomCreationConverter to a custom JsonConverter.ReadJson that handles null explicitly.

Example fix

// before: Create returns null for unhandled types
public override IFoo Create(Type objectType) =>
    objectType == typeof(Foo) ? new Foo() : null;

// after: always return a concrete instance
public override IFoo Create(Type objectType) =>
    objectType == typeof(SpecialFoo) ? new SpecialFoo() : new Foo();
Defensive patterns

Strategy: validation

Validate before calling

T instance = converter.Create(objectType);
if (instance == null)
    throw new InvalidOperationException($"Create returned null for {objectType}");

Type guard

static bool CreateReturnsInstance(CustomCreationConverter<IFoo> c, Type t) =>
    c.Create(t) != null;

Try / catch

try { var obj = serializer.Deserialize<IFoo>(reader); }
catch (JsonSerializationException ex) when (ex.Message.Contains("No object created"))
{
    throw new InvalidOperationException("Factory/DI returned null during deserialization", ex);
}

Prevention

When it happens

Trigger: Implementing Create(Type objectType) such that it returns null for some objectType (e.g. a fallback path, an unhandled subtype, or a DI container failing to resolve). During deserialization of a property whose converter is a CustomCreationConverter, Create returns null and the error fires.

Common situations: A factory/DI container returns null when the requested type is not registered. A switch in Create that has no default case. Returning null to mean 'not supported' instead of throwing, which then surfaces as this generic error during deserialization.

Related errors


AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07). Data as JSON: /api/errors/7ecce5c745f00d2d. Report an issue: GitHub.