{"record":{"id":"7121a3d656912a3c","repo":"JamesNK/Newtonsoft.Json","slug":"no-parameterless-constructor-defined-for-0","errorCode":null,"errorMessage":"No parameterless constructor defined for '{0}'.","messagePattern":"No parameterless constructor defined for '(.+?)'\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs","lineNumber":300,"sourceCode":"\n                            return param.GetType();\n                        }).ToArray();\n                        ConstructorInfo? parameterizedConstructorInfo = type.GetConstructor(paramTypes);\n\n                        if (parameterizedConstructorInfo != null)\n                        {\n                            ObjectConstructor<object> parameterizedConstructor = ReflectionDelegateFactory.CreateParameterizedConstructor(parameterizedConstructorInfo);\n                            return parameterizedConstructor(parameters);\n                        }\n                        else\n                        {\n                            throw new JsonException(\"No matching parameterized constructor found for '{0}'.\".FormatWith(CultureInfo.InvariantCulture, type));\n                        }\n                    }\n\n                    if (defaultConstructor == null)\n                    {\n                        throw new JsonException(\"No parameterless constructor defined for '{0}'.\".FormatWith(CultureInfo.InvariantCulture, type));\n                    }\n\n                    return defaultConstructor();\n                }\n                catch (Exception ex)\n                {\n                    throw new JsonException(\"Error creating '{0}'.\".FormatWith(CultureInfo.InvariantCulture, type), ex);\n                }\n            };\n        }\n\n#if !(NET20 || DOTNET)\n        [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        private static Type? GetAssociatedMetadataType(Type type)\n        {\n            return AssociatedMetadataTypesCache.Instance.Get(type);\n        }","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs#L282-L318","documentation":"Thrown by GetCreator's lambda when no parameters were supplied and the target type (a JsonConverter or NamingStrategy) has no accessible default (parameterless) constructor. '{0}' is the offending type.","triggerScenarios":"Using [JsonConverter(typeof(T))] (no arguments) on a converter/naming-strategy T that only has parameterized constructors, or calling CreateJsonConverterInstance(type, null) for such a type.","commonSituations":"A converter that requires configuration but is referenced without arguments; refactoring a converter to require constructor arguments while leaving the attribute unchanged; third-party converters that intentionally have no default constructor.","solutions":["Supply the required arguments via [JsonConverter(typeof(T), arg1, ...)].","Add a public parameterless constructor to T.","Instantiate the converter manually and add it to JsonSerializerSettings.Converters instead of using the attribute.","If T is a third-party type, register a pre-built instance via settings.Converters.Add(new T(...))."],"exampleFix":"// before: converter has no default ctor but attribute omits args\n[JsonConverter(typeof(FormatConverter))]\npublic DateTime When { get; set; }\npublic FormatConverter(string format) { ... }\n// after: pass the required arg\n[JsonConverter(typeof(FormatConverter), \"yyyy-MM-dd\")]\npublic DateTime When { get; set; }","handlingStrategy":"validation","validationCode":"if (type.GetConstructor(Type.EmptyTypes) == null) throw new InvalidOperationException(\"converter has no default ctor; supply args or register an instance\");","typeGuard":"static bool HasDefaultCtor(Type t) => t.GetConstructor(Type.EmptyTypes) != null;","tryCatchPattern":"try { JsonTypeReflector.CreateJsonConverterInstance(type, null); }\ncatch (JsonException ex) when (ex.Message.Contains(\"No parameterless constructor\")) {\n    logger.Error(ex, \"converter requires args; pass via [JsonConverter(typeof(T), ...)] or register an instance.\"); throw;\n}","preventionTips":["Either add a public parameterless constructor to custom converters or always pass required args.","For third-party converters without a default ctor, register pre-built instances via settings.Converters.","Keep [JsonConverter(...)] attribute args in sync with the converter's constructor surface.","Unit-test converter instantiation paths."],"tags":["converter","naming-strategy","reflection","constructor"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}