babalae/better-genshin-impact · warning · ArgumentException
无法找到名称为 '{name}' 的枚举值
Error message
无法找到名称为 '{name}' 的枚举值 What it means
Thrown by MapTypesExtensions.ParseFromName when Enum.TryParse<MapTypes>(name, true, out var result) fails. The parse is case-insensitive (ignoreCase=true), so it fails only when 'name' is not the textual representation of any MapTypes member (e.g. 'Teyvat', 'TheChasm'). Used to convert a map-type name string to the enum.
Source
Thrown at BetterGenshinImpact/GameTask/Common/Map/Maps/Base/MapTypes.cs:52
{
if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)
{
if (attribute.Description == description)
{
return (MapTypes)field.GetValue(null)!;
}
}
}
throw new ArgumentException($"无法找到描述为 '{description}' 的枚举值", nameof(description));
}
public static MapTypes ParseFromName(string name)
{
if (Enum.TryParse<MapTypes>(name, true, out var result))
{
return result;
}
throw new ArgumentException($"无法找到名称为 '{name}' 的枚举值", nameof(name));
}
}View on GitHub (pinned to a7cb36712d)
Solutions
- Use the exact enum member name (e.g. 'Teyvat', 'TheChasm') in config; the parse is case-insensitive so casing is flexible.
- Trim the input and verify against Enum.GetNames<MapTypes>().
- If you intended to pass a human label (description), call ParseFromDescription instead.
- Add validation/warning when the name isn't recognized before it reaches this throw.
Example fix
// before — throws on bad input
public static MapTypes ParseFromName(string name)
{
if (Enum.TryParse<MapTypes>(name, true, out var result)) return result;
throw new ArgumentException(...);
}
// after — accept both names and descriptions, and trim
public static MapTypes ParseFromName(string name)
{
if (Enum.TryParse<MapTypes>(name?.Trim(), true, out var result)) return result;
// fall back to description match
return ParseFromDescription(name!.Trim());
} Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.TryParse<MapTypes>(name?.Trim(), true, out _))
throw new ArgumentException($"无效的地图名称: {name},可用值: {string.Join(", ", Enum.GetNames<MapTypes>())}"); Type guard
static bool IsValidMapName(string? n) => Enum.TryParse<MapTypes>(n?.Trim(), true, out _);
Prevention
- Use exact enum member names in config (case-insensitive).
- Validate at the config load boundary and report valid options.
When it happens
Trigger: ParseFromName receives a string that is not a member name (case-insensitive). MapManager.GetMap(string mapName,...) calls ParseFromName(mapName), so any external/config map name that isn't a valid enum member name triggers this.
Common situations: Config or pathing JSON uses a map name like 'teyvat大陆' or a description instead of the enum name; a renamed/removed member; typos; whitespace in the name; full-width vs half-width characters.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4cbf42deba2e2b38.
Report an issue: GitHub.