LuckyPennySoftware/AutoMapper · error · ArgumentOutOfRangeException
Cannot find any profiles with the name '{profileName}'.
Error message
Cannot find any profiles with the name '{profileName}'. What it means
Thrown by AssertConfigurationIsValid(string profileName) when no registered Profile has a Name property matching the supplied argument. The method uses Array.TrueForAll to check that no profile name matches, then throws ArgumentOutOfRangeException. The default Profile.Name is the fully-qualified type name of the profile class.
Source
Thrown at src/AutoMapper/Configuration/MapperConfiguration.cs:521
IObjectMapper IGlobalConfiguration.FindMapper(TypePair types) => FindMapper(types);
IObjectMapper FindMapper(TypePair types)
{
foreach (var mapper in _mappers)
{
if (mapper.IsMatch(types))
{
return mapper;
}
}
return null;
}
void IGlobalConfiguration.RegisterTypeMap(TypeMap typeMap) => _configuredMaps[typeMap.Types] = typeMap;
void IGlobalConfiguration.AssertConfigurationIsValid(TypeMap typeMap) => Validator().AssertConfigurationIsValid([typeMap]);
void IGlobalConfiguration.AssertConfigurationIsValid(string profileName)
{
if (Array.TrueForAll(Profiles, x => x.Name != profileName))
{
throw new ArgumentOutOfRangeException(nameof(profileName), $"Cannot find any profiles with the name '{profileName}'.");
}
Validator().AssertConfigurationIsValid(_configuredMaps.Values.Where(typeMap => typeMap.Profile.Name == profileName).ToArray());
}
void IGlobalConfiguration.AssertConfigurationIsValid<TProfile>() => this.Internal().AssertConfigurationIsValid(typeof(TProfile).FullName);
void IGlobalConfiguration.RegisterAsMap(TypeMapConfiguration typeMapConfiguration) =>
_resolvedMaps[typeMapConfiguration.Types] = GetIncludedTypeMap(new(typeMapConfiguration.SourceType, typeMapConfiguration.DestinationTypeOverride));
string IGlobalConfiguration.LicenseKey => _configurationExpression.LicenseKey;
}
struct LazyValue<T>(Func<T> factory) where T : class
{
readonly Func<T> _factory = factory;
T _value = null;
public T Value => LazyInitializer.EnsureInitialized(ref _value, _factory);
}View on GitHub (pinned to dfa6dd587c)
Solutions
- Use the generic overload AssertConfigurationIsValid<OrderProfile>() which resolves the name automatically via typeof(TProfile).FullName.
- Inspect Profile.Name — it defaults to typeof(T).FullName unless overridden in the constructor.
- If you set a custom Name in the Profile constructor (Profile.Name = "Short"), use that exact string.
- Verify the profile is actually registered via AddProfile<T>() or AddProfiles().
Example fix
// before — name mismatch (Profile.Name defaults to fully qualified name)
mapper.ConfigurationProvider.AssertConfigurationIsValid("OrderProfile");
// after — use the generic overload
cfg.AssertConfigurationIsValid<OrderProfile>();
// or set a short name and use it
public class OrderProfile : Profile { public OrderProfile() { Profile.Name = "Orders"; } }
mapper.ConfigurationProvider.AssertConfigurationIsValid("Orders"); Defensive patterns
Strategy: validation
Validate before calling
// Validate the profile name exists before calling AssertConfigurationIsValid
var profileName = "MyProfile";
if (!config.Profiles.Any(p => p.Name == profileName))
throw new InvalidOperationException($"Profile '{profileName}' not found. Available: {string.Join(", ", config.Profiles.Select(p => p.Name))}");
// Or simply use the generic overload to avoid string-based lookup:
// config.AssertConfigurationIsValid<MyProfile>(); Prevention
- Prefer the generic overload AssertConfigurationIsValid<TProfile>() to avoid string-based name lookups.
- If using string names, set Profile.Name explicitly in the constructor for stability.
- Remember the default Profile.Name is the fully qualified type name.
- Log available profile names during startup for easy debugging.
When it happens
Trigger: Calling mapper.ConfigurationProvider.AssertConfigurationIsValid("MyProfile") where the string does not match any Profile.Name. Common mistake: passing the short class name when Profile.Name defaults to the fully qualified name.
Common situations: Using the class name "OrderProfile" instead of the full name "MyApp.Profiles.OrderProfile"; typo in the profile name string; profile was not registered in the configuration.
Related errors
- Duplicate CreateMap calls: {error.Types.SourceType.FullName}
- The type {typeMap.DestinationType.Name} does not have a cons
- {typeMap.DestinationType.Name} does not have a matching cons
- Only member accesses are allowed. {destinationMember}
- Type '{conditionType.Name}' does not implement ICondition<TS
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/5591edc486c51413.
Report an issue: GitHub.