{"record":{"id":"7ecce5c745f00d2d","repo":"JamesNK/Newtonsoft.Json","slug":"no-object-created","errorCode":null,"errorMessage":"No object created.","messagePattern":"No object created\\.","errorType":"exception","errorClass":"JsonSerializationException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs","lineNumber":70,"sourceCode":"        /// <summary>\n        /// Reads the JSON representation of the object.\n        /// </summary>\n        /// <param name=\"reader\">The <see cref=\"JsonReader\"/> to read from.</param>\n        /// <param name=\"objectType\">Type of the object.</param>\n        /// <param name=\"existingValue\">The existing value of object being read.</param>\n        /// <param name=\"serializer\">The calling serializer.</param>\n        /// <returns>The object value.</returns>\n        public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)\n        {\n            if (reader.TokenType == JsonToken.Null)\n            {\n                return null;\n            }\n\n            T value = Create(objectType);\n            if (value == null)\n            {\n                throw new JsonSerializationException(\"No object created.\");\n            }\n\n            serializer.Populate(reader, value);\n            return value;\n        }\n\n        /// <summary>\n        /// Creates an object which will then be populated by the serializer.\n        /// </summary>\n        /// <param name=\"objectType\">Type of the object.</param>\n        /// <returns>The created object.</returns>\n        public abstract T Create(Type objectType);\n\n        /// <summary>\n        /// Determines whether this instance can convert the specified object type.\n        /// </summary>\n        /// <param name=\"objectType\">Type of the object.</param>\n        /// <returns>","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make Create(Type) always return a non-null instance; add a default branch that throws a descriptive exception or returns a concrete fallback.","Check your DI/factory registration covers every objectType the deserializer can request.","If null is legitimately possible, switch from CustomCreationConverter to a custom JsonConverter.ReadJson that handles null explicitly."],"exampleFix":"// before: Create returns null for unhandled types\npublic override IFoo Create(Type objectType) =>\n    objectType == typeof(Foo) ? new Foo() : null;\n\n// after: always return a concrete instance\npublic override IFoo Create(Type objectType) =>\n    objectType == typeof(SpecialFoo) ? new SpecialFoo() : new Foo();","handlingStrategy":"validation","validationCode":"T instance = converter.Create(objectType);\nif (instance == null)\n    throw new InvalidOperationException($\"Create returned null for {objectType}\");","typeGuard":"static bool CreateReturnsInstance(CustomCreationConverter<IFoo> c, Type t) =>\n    c.Create(t) != null;","tryCatchPattern":"try { var obj = serializer.Deserialize<IFoo>(reader); }\ncatch (JsonSerializationException ex) when (ex.Message.Contains(\"No object created\"))\n{\n    throw new InvalidOperationException(\"Factory/DI returned null during deserialization\", ex);\n}","preventionTips":["Make Create(Type) always return a non-null instance; add a default branch.","Ensure the DI/factory registration covers every deserializable subtype.","Unit-test Create for every type the deserializer may request."],"tags":["deserialization","converter","custom-creation","null-reference"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}