JamesNK/Newtonsoft.Json · error · JsonException

No parameterless constructor defined for '{0}'.

Error message

No parameterless constructor defined for '{0}'.

What it means

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.

Source

Thrown at Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs:300

                            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)
        [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
        private static Type? GetAssociatedMetadataType(Type type)
        {
            return AssociatedMetadataTypesCache.Instance.Get(type);
        }

View on GitHub (pinned to 4f73e74372)

Solutions

  1. Supply the required arguments via [JsonConverter(typeof(T), arg1, ...)].
  2. Add a public parameterless constructor to T.
  3. Instantiate the converter manually and add it to JsonSerializerSettings.Converters instead of using the attribute.
  4. If T is a third-party type, register a pre-built instance via settings.Converters.Add(new T(...)).

Example fix

// before: converter has no default ctor but attribute omits args
[JsonConverter(typeof(FormatConverter))]
public DateTime When { get; set; }
public FormatConverter(string format) { ... }
// after: pass the required arg
[JsonConverter(typeof(FormatConverter), "yyyy-MM-dd")]
public DateTime When { get; set; }
Defensive patterns

Strategy: validation

Validate before calling

if (type.GetConstructor(Type.EmptyTypes) == null) throw new InvalidOperationException("converter has no default ctor; supply args or register an instance");

Type guard

static bool HasDefaultCtor(Type t) => t.GetConstructor(Type.EmptyTypes) != null;

Try / catch

try { JsonTypeReflector.CreateJsonConverterInstance(type, null); }
catch (JsonException ex) when (ex.Message.Contains("No parameterless constructor")) {
    logger.Error(ex, "converter requires args; pass via [JsonConverter(typeof(T), ...)] or register an instance."); throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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