LuckyPennySoftware/AutoMapper · error · ArgumentOutOfRangeException
Cannot find suitable method {type}.{methodName}({parametersC
Error message
Cannot find suitable method {type}.{methodName}({parametersCount} parameters). What it means
Internal error thrown by TypeExtensions.StaticGenericMethod when no public static generic method (IsGenericMethodDefinition) with the specified name and parameter count exists on the type. The method searches via GetMember with StaticFlags minus NonPublic. This is an internal reflection helper used by AutoMapper's own code paths, not typically called by end users directly.
Source
Thrown at src/AutoMapper/Internal/TypeExtensions.cs:19
using System.Collections;
using System.Dynamic;
namespace AutoMapper.Internal;
public static class TypeExtensions
{
public const BindingFlags InstanceFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
public const BindingFlags StaticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
public static MethodInfo StaticGenericMethod(this Type type, string methodName, int parametersCount)
{
foreach (MethodInfo foundMethod in type.GetMember(methodName, MemberTypes.Method, StaticFlags & ~BindingFlags.NonPublic))
{
if (foundMethod.IsGenericMethodDefinition && foundMethod.GetParameters().Length == parametersCount)
{
return foundMethod;
}
}
throw new ArgumentOutOfRangeException(nameof(methodName), $"Cannot find suitable method {type}.{methodName}({parametersCount} parameters).");
}
public static void CheckIsDerivedFrom(this Type derivedType, Type baseType)
{
if (!baseType.IsAssignableFrom(derivedType) && !derivedType.IsGenericTypeDefinition && !baseType.IsGenericTypeDefinition)
{
throw new ArgumentOutOfRangeException(nameof(derivedType), $"{derivedType} is not derived from {baseType}.");
}
}
public static bool IsDynamic(this Type type) => typeof(IDynamicMetaObjectProvider).IsAssignableFrom(type);
public static IEnumerable<Type> BaseClassesAndInterfaces(this Type type)
{
var currentType = type;
while ((currentType = currentType.BaseType) != null)
{
yield return currentType;View on GitHub (pinned to dfa6dd587c)
Solutions
- Check the call stack to identify which type and method name AutoMapper was searching for.
- Ensure all referenced AutoMapper packages are the same version across the solution.
- If using custom mappers or extensions, verify the types they return have the expected static generic methods.
- File a bug report with the full stack trace if using standard AutoMapper APIs.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
var config = new MapperConfiguration(cfg => { /* ... */ });
config.CompileMaps();
}
catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains("Cannot find suitable method"))
{
// Inspect the stack trace to find which type/method AutoMapper was searching for
logger.LogError(ex, "Internal reflection lookup failed. Check AutoMapper version consistency.");
} Prevention
- Ensure all AutoMapper NuGet packages across the solution reference the same version.
- Keep custom IObjectMapper implementations in sync with the AutoMapper API surface.
- Report internal reflection errors with a full reproduction if using standard APIs.
When it happens
Trigger: AutoMapper's internal code calls StaticGenericMethod for an expected method name on a type, but that method does not exist — typically due to a version mismatch, a missing extension method, or a type that does not have the expected static generic method.
Common situations: Referenced AutoMapper version is inconsistent across assemblies; a custom IObjectMapper or extension returns a type missing an expected method; extremely rare for standard usage.
Related errors
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/68b67e3e7182d14d.
Report an issue: GitHub.