JamesNK/Newtonsoft.Json · error · JsonException
No matching parameterized constructor found for '{0}'.
Error message
No matching parameterized constructor found for '{0}'. What it means
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).
Source
Thrown at Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs:294
Type[] paramTypes = parameters.Select(param =>
{
if (param == null)
{
throw new InvalidOperationException("Cannot pass a null parameter to the constructor.");
}
return param.GetType();
}).ToArray();
ConstructorInfo? parameterizedConstructorInfo = type.GetConstructor(paramTypes);
if (parameterizedConstructorInfo != null)
{
ObjectConstructor<object> parameterizedConstructor = ReflectionDelegateFactory.CreateParameterizedConstructor(parameterizedConstructorInfo);
return parameterizedConstructor(parameters);
}
else
{
throw new JsonException("No matching parameterized constructor found for '{0}'.".FormatWith(CultureInfo.InvariantCulture, type));
}
}
if (defaultConstructor == null)
{
throw new JsonException("No parameterless constructor defined for '{0}'.".FormatWith(CultureInfo.InvariantCulture, type));
}
return defaultConstructor();
}
catch (Exception ex)
{
throw new JsonException("Error creating '{0}'.".FormatWith(CultureInfo.InvariantCulture, type), ex);
}
};
}
#if !(NET20 || DOTNET)View on GitHub (pinned to 4f73e74372)
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.
Example fix
// before: attribute args don't match any ctor
[JsonConverter(typeof(MyConv), 123)] // ctor expects string
public string Name { get; set; }
// after: align types
[JsonConverter(typeof(MyConv), "123")]
public string Name { get; set; }
// or add an int overload: public MyConv(int code) {...} Defensive patterns
Strategy: validation
Validate before calling
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))); Try / catch
try { JsonTypeReflector.CreateJsonConverterInstance(type, args); }
catch (JsonException ex) when (ex.Message.Contains("No matching parameterized constructor")) {
logger.Error(ex, "converter ctor signature mismatch; align attribute arg types."); throw;
} Prevention
- 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.
When it happens
Trigger: [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.
Common situations: 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.
Related errors
- Cannot pass a null parameter to the constructor.
- No parameterless constructor defined for '{0}'.
- Error creating '{0}'.
- Could not get constructor for {0}.
- Unable to find default constructor for
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/8cd1586130686615.
Report an issue: GitHub.