LuckyPennySoftware/AutoMapper · error · ArgumentOutOfRangeException
Cannot find member {name} of type {type}.
Error message
Cannot find member {name} of type {type}. What it means
Thrown by GetInheritedMethod when no instance method with the given name can be found on the type, its base classes, or its implemented interfaces. The method searches the type first, then walks BaseClassesAndInterfaces. This is called internally by reflection helpers such as GetMemberPath when resolving a dotted member path where a segment is neither a property nor a field, so it falls through to a method lookup.
Source
Thrown at src/AutoMapper/Internal/TypeExtensions.cs:52
var currentType = type;
while ((currentType = currentType.BaseType) != null)
{
yield return currentType;
}
foreach (var interfaceType in type.GetInterfaces())
{
yield return interfaceType;
}
}
public static PropertyInfo GetInheritedProperty(this Type type, string name) => type.GetProperty(name, InstanceFlags) ?? type.GetBaseProperty(name);
static PropertyInfo GetBaseProperty(this Type type, string name) =>
type.BaseClassesAndInterfaces().Select(t => t.GetProperty(name, InstanceFlags)).FirstOrDefault(p => p != null);
public static FieldInfo GetInheritedField(this Type type, string name) => type.GetField(name, InstanceFlags) ?? type.GetBaseField(name);
static FieldInfo GetBaseField(this Type type, string name) =>
type.BaseClassesAndInterfaces().Select(t => t.GetField(name, InstanceFlags)).FirstOrDefault(f => f != null);
public static MethodInfo GetInheritedMethod(this Type type, string name) => type.GetInstanceMethod(name) ?? type.GetBaseMethod(name) ??
throw new ArgumentOutOfRangeException(nameof(name), $"Cannot find member {name} of type {type}.");
static MethodInfo GetBaseMethod(this Type type, string name) =>
type.BaseClassesAndInterfaces().Select(t => t.GetInstanceMethod(name)).FirstOrDefault(m => m != null);
public static MemberInfo GetFieldOrProperty(this Type type, string name)
=> type.GetInheritedProperty(name) ?? (MemberInfo)type.GetInheritedField(name) ?? throw new ArgumentOutOfRangeException(nameof(name), $"Cannot find member {name} of type {type}.");
public static bool IsNullableType(this Type type) => type.IsGenericType(typeof(Nullable<>));
public static Type GetICollectionType(this Type type) => type.GetGenericInterface(typeof(ICollection<>));
public static bool IsCollection(this Type type) => type != typeof(string) && typeof(IEnumerable).IsAssignableFrom(type);
public static bool IsListType(this Type type) => typeof(IList).IsAssignableFrom(type);
public static bool IsGenericType(this Type type, Type genericType) => type.IsGenericType && type.GetGenericTypeDefinition() == genericType;
public static Type GetIEnumerableType(this Type type) => type.GetGenericInterface(typeof(IEnumerable<>));
View on GitHub (pinned to dfa6dd587c)
Solutions
- Verify each segment in the dotted member path string exists as a property, field, or instance method on the source type.
- Prefer lambda-based MapFrom(s => s.Prop.SubProp) for compile-time safety and IntelliSense.
- Check for typos and case-sensitivity in the member path string.
Example fix
// before — misspelled member in string path
CreateMap<Source, Dest>().ForMember("Value", opt => opt.MapFrom("CalcualtedValue"));
// after — correct name or use lambda
CreateMap<Source, Dest>().ForMember("Value", opt => opt.MapFrom(s => s.CalculatedValue)); Defensive patterns
Strategy: validation
Validate before calling
// Validate that a method exists on the source type before using it in a dotted path
var methodName = "GetData";
if (typeof(TSource).GetInstanceMethod(methodName) == null &&
!typeof(TSource).BaseClassesAndInterfaces().Any(t => t.GetInstanceMethod(methodName) != null))
throw new MissingMethodException(typeof(TSource).Name, methodName); Prevention
- Prefer lambda-based MapFrom over string-based dotted paths for compile-time safety.
- When using string paths, verify each segment exists as a property, field, or instance method.
- Check for typos and case-sensitivity in member path strings.
When it happens
Trigger: Calling MapFrom("dotted.path") where a path segment is not a property or field and also not a method on the source type; or an internal lookup for a method name that was renamed or removed.
Common situations: Misspelled member name in a string-based MapFrom path; renamed a method after writing the mapping; dotted path referencing a member that exists on a different overload or is static rather than instance.
Related errors
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/2bc398fb03ae1627.
Report an issue: GitHub.