JamesNK/Newtonsoft.Json · error · ArgumentException
Unexpected member type '{0}' for member '{1}'.
Error message
Unexpected member type '{0}' for member '{1}'. What it means
Thrown by ReflectionObject.Create's switch default case when a resolved member's MemberType is not Field, Property, or Method. ReflectionObject only wires up fields, properties, and zero-or-one-argument methods; events, nested types, constructors, and TypeInfo fall into this default branch.
Source
Thrown at Src/Newtonsoft.Json/Utilities/ReflectionObject.cs:170
case MemberTypes.Method:
MethodInfo method = (MethodInfo)member;
if (method.IsPublic)
{
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 0 && method.ReturnType != typeof(void))
{
MethodCall<object, object?> call = delegateFactory.CreateMethodCall<object>(method);
reflectionMember.Getter = target => call(target);
}
else if (parameters.Length == 1 && method.ReturnType == typeof(void))
{
MethodCall<object, object?> call = delegateFactory.CreateMethodCall<object>(method);
reflectionMember.Setter = (target, arg) => call(target, arg);
}
}
break;
default:
throw new ArgumentException("Unexpected member type '{0}' for member '{1}'.".FormatWith(CultureInfo.InvariantCulture, member.MemberType(), member.Name));
}
reflectionMember.MemberType = ReflectionUtils.GetMemberUnderlyingType(member);
d.Members[memberName] = reflectionMember;
}
return d;
}
}
}
View on GitHub (pinned to 4f73e74372)
Solutions
- Use a member name that refers to a field, property, or suitable method (parameterless with a return, or single-param void).
- Avoid passing names of events or nested types to ReflectionObject.Create.
- Inspect member.MemberType before calling Create to filter to supported kinds.
Example fix
// before var ro = ReflectionObject.Create(typeof(Foo), "Clicked"); // 'Clicked' is an event -> Unexpected member type 'Event' // after var ro = ReflectionObject.Create(typeof(Foo), "Value"); // Value is a property
Defensive patterns
Strategy: validation
Validate before calling
MemberTypes supported = MemberTypes.Field | MemberTypes.Property | MemberTypes.Method;
MemberInfo m = type.GetMember(name, BindingFlags.Instance | BindingFlags.Public).Single();
if ((m.MemberType & supported) == 0) throw new ArgumentException($"{m.MemberType} not supported"); Type guard
static bool IsSupportedMember(MemberInfo m) => m.MemberType is MemberTypes.Field or MemberTypes.Property or MemberTypes.Method;
Prevention
- Check member.MemberType against Field/Property/Method before calling ReflectionObject.Create.
- Avoid names that collide with events or nested types.
- Document which member kinds ReflectionObject supports for your team.
When it happens
Trigger: Calling ReflectionObject.Create with a member name that resolves to an EventInfo, a nested type, or a constructor rather than a field/property/method.
Common situations: A type that has an event or nested type whose name shadows the intended field/property, or exploration/tooling code that passes arbitrary member names found via reflection.
Related errors
- Expected a single member with the name '{0}'.
- MemberInfo must be of type FieldInfo, PropertyInfo, EventInf
- MemberInfo '{0}' is not of type FieldInfo or PropertyInfo
- MemberInfo '{0}' must be of type FieldInfo or PropertyInfo
- type
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/9cc19589cd24e5cc.
Report an issue: GitHub.