JamesNK/Newtonsoft.Json · error · ArgumentException
MemberInfo '{0}' has index parameters
Error message
MemberInfo '{0}' has index parameters What it means
Thrown by ReflectionUtils.GetMemberValue when PropertyInfo.GetValue throws TargetParameterCountException because the property requires index parameters (an indexer). It wraps the inner TargetParameterCountException. Indexed properties such as C# `this[int]` cannot be read without supplying an index.
Source
Thrown at Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs:546
/// <param name="target">The target object.</param>
/// <returns>The member's value on the object.</returns>
public static object? GetMemberValue(MemberInfo member, object target)
{
ValidationUtils.ArgumentNotNull(member, nameof(member));
ValidationUtils.ArgumentNotNull(target, nameof(target));
switch (member.MemberType())
{
case MemberTypes.Field:
return ((FieldInfo)member).GetValue(target);
case MemberTypes.Property:
try
{
return ((PropertyInfo)member).GetValue(target, null);
}
catch (TargetParameterCountException e)
{
throw new ArgumentException("MemberInfo '{0}' has index parameters".FormatWith(CultureInfo.InvariantCulture, member.Name), e);
}
default:
throw new ArgumentException("MemberInfo '{0}' is not of type FieldInfo or PropertyInfo".FormatWith(CultureInfo.InvariantCulture, member.Name), nameof(member));
}
}
/// <summary>
/// Sets the member's value on the target object.
/// </summary>
/// <param name="member">The member.</param>
/// <param name="target">The target.</param>
/// <param name="value">The value.</param>
public static void SetMemberValue(MemberInfo member, object target, object? value)
{
ValidationUtils.ArgumentNotNull(member, nameof(member));
ValidationUtils.ArgumentNotNull(target, nameof(target));
switch (member.MemberType())View on GitHub (pinned to 4f73e74372)
Solutions
- Skip indexed properties: check propertyInfo.GetIndexParameters().Length == 0 before reading.
- If you must read an indexer, call PropertyInfo.GetValue directly with the index arguments.
- Annotate indexers with [JsonIgnore] to exclude them from serialization.
Example fix
// before
var value = ReflectionUtils.GetMemberValue(indexerProperty, target);
// after
if (((PropertyInfo)indexerProperty).GetIndexParameters().Length == 0)
var value = ReflectionUtils.GetMemberValue(indexerProperty, target); Defensive patterns
Strategy: validation
Validate before calling
if (member is PropertyInfo p && p.GetIndexParameters().Length > 0)
throw new ArgumentException($"{p.Name} is an indexer; use GetValue with index args."); Type guard
static bool IsIndexer(PropertyInfo p) => p.GetIndexParameters().Length > 0;
Prevention
- Skip indexed properties when walking PropertyInfos (check GetIndexParameters().Length).
- Annotate indexers with [JsonIgnore].
- Use PropertyInfo.GetValue directly with index arguments when an indexer must be read.
When it happens
Trigger: Calling GetMemberValue on a PropertyInfo whose GetIndexParameters().Length > 0 (an indexer). Internally can occur when a serializer or utility walks all properties including indexers.
Common situations: Custom serializers iterating PropertyInfo collections that include indexers, types with indexers mistaken for ordinary properties, or dictionary-like wrapper types exposing `this[object]`.
Related errors
- Property '{0}' does not have a getter.
- Property does not have a getter.
- Property does not have a setter.
- Could not create getter for {0}. ByRef return values are not
- Accessed JArray values with invalid key value: {0}. Int32 ar
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/ff879669b14d75dd.
Report an issue: GitHub.