{"record":{"id":"8cd1586130686615","repo":"JamesNK/Newtonsoft.Json","slug":"no-matching-parameterized-constructor-found-for","errorCode":null,"errorMessage":"No matching parameterized constructor found for '{0}'.","messagePattern":"No matching parameterized constructor found for '(.+?)'\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs","lineNumber":294,"sourceCode":"                        Type[] paramTypes = parameters.Select(param =>\n                        {\n                            if (param == null)\n                            {\n                                throw new InvalidOperationException(\"Cannot pass a null parameter to the constructor.\");\n                            }\n\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)","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs#L276-L312","documentation":"Thrown by GetCreator's parameterized lambda when parameters were supplied but no public constructor on the target type matches the exact runtime types of those parameters. '{0}' is the type that was being instantiated (a JsonConverter or NamingStrategy type).","triggerScenarios":"[JsonConverter(typeof(T), arg1, arg2)] where the argument runtime types do not exactly match any public constructor of T, or calling CreateJsonConverterInstance(type, args) with mismatched argument types. GetConstructor uses the exact runtime types, so subclass arguments won't bind to base-class parameters.","commonSituations":"Passing a derived type where the constructor expects a base type (GetConstructor is invariant), passing a string where the constructor expects an enum or numeric type, misspelled/mis-typed converter constructor arguments, or a converter that was refactored to change its constructor signature while old attributes still pass the old args.","solutions":["Inspect the converter/naming-strategy type's public constructors and match the attribute's argument types exactly.","If you need looser binding, write a custom JsonConverterAttribute whose CreateJsonConverter creates the instance via your own resolution logic.","Ensure runtime argument types match the parameter types declared (a stringly-typed value may need explicit conversion).","Update the [JsonConverter(...)] attribute arguments after refactoring the converter's constructor."],"exampleFix":"// before: attribute args don't match any ctor\n[JsonConverter(typeof(MyConv), 123)] // ctor expects string\npublic string Name { get; set; }\n// after: align types\n[JsonConverter(typeof(MyConv), \"123\")]\npublic string Name { get; set; }\n// or add an int overload: public MyConv(int code) {...}","handlingStrategy":"validation","validationCode":"var sig = args.Select(a => a.GetType()).ToArray(); if (type.GetConstructor(sig) == null) throw new InvalidOperationException(\"no ctor matches \" + string.Join(\",\", sig.Select(t=>t.Name)));","typeGuard":null,"tryCatchPattern":"try { JsonTypeReflector.CreateJsonConverterInstance(type, args); }\ncatch (JsonException ex) when (ex.Message.Contains(\"No matching parameterized constructor\")) {\n    logger.Error(ex, \"converter ctor signature mismatch; align attribute arg types.\"); throw;\n}","preventionTips":["Match [JsonConverter(typeof(T), args)] argument types exactly to a public constructor of T.","Remember GetConstructor is invariant: pass the exact parameter types.","Update attribute arguments after refactoring converter constructors.","Unit-test converter instantiation with attribute-supplied arguments."],"tags":["converter","naming-strategy","reflection","constructor","argument-mismatch"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}