{"record":{"id":"ac79252a688ed029","repo":"Humanizr/Humanizer","slug":"couldn-t-find-any-enum-member-that-matches-the-str","errorCode":null,"errorMessage":"Couldn't find any enum member that matches the string '{input}'","messagePattern":"Couldn't find any enum member that matches the string '(.+?)'","errorType":"exception","errorClass":"NoMatchFoundException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/EnumDehumanizeExtensions.cs","lineNumber":152,"sourceCode":"            throw exception.InnerException!;\n        }\n    }\n\n    static T? DehumanizeToPrivate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(string input, OnNoMatch onNoMatch)\n        where T : struct, Enum\n    {\n        var dehumanized = EnumCache<T>.GetDehumanized();\n        if (dehumanized.TryGetValue(input, out var value))\n        {\n            return value;\n        }\n\n        if (onNoMatch != OnNoMatch.ThrowsException)\n        {\n            return null;\n        }\n\n        throw new NoMatchFoundException($\"Couldn't find any enum member that matches the string '{input}'\");\n    }\n}","sourceCodeStart":134,"sourceCodeEnd":154,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/EnumDehumanizeExtensions.cs#L134-L154","documentation":"Thrown by DehumanizeTo<T> (the throwing overload) when no enum member matches the input string. Matching is case-insensitive against the enum member name, its humanized form, and configured metadata aliases (DisplayAttribute Name/Description/ShortName, DescriptionAttribute). The custom NoMatchFoundException message echoes the offending input. The nullable overload with OnNoMatch.ReturnsNull returns null instead.","triggerScenarios":"Calling \"Bad Value\".DehumanizeTo<MyEnum>() where no member humanizes to 'Bad Value'; dehumanizing a localized display string whose culture differs from what was used to humanize; whitespace or case variants that the matcher does not normalize (matching does NOT trim whitespace); passing user input directly without validation.","commonSituations":"Round-tripping enums through an external system that altered the string (extra spaces, different locale, a different metadata attribute used at write time); accepting free-text enum selection from a user without validating against known values; version skew where an enum member was renamed/removed but stored strings persist.","solutions":["Use the overload \"input\".DehumanizeTo<MyEnum>(OnNoMatch.ReturnsNull) and handle the null result explicitly.","Pre-validate input against the set of humanized enum values (typeof(MyEnum).GetValues()...Humanize()) before calling.","Catch NoMatchFoundException specifically (not the general Exception) and present a 'no matching value' error to the user."],"exampleFix":"// before\nvar value = userInput.DehumanizeTo<MyEnum>(); // throws NoMatchFoundException\n\n// after\nvar value = userInput.DehumanizeTo<MyEnum>(OnNoMatch.ReturnsNull);\nif (value is null)\n    return BadRequest($\"Unknown value '{userInput}'.\");","handlingStrategy":"fallback","validationCode":"// Prefer the non-throwing overload:\nvar value = input.DehumanizeTo<MyEnum>(OnNoMatch.ReturnsNull);\nif (value is null) return NotFound($\"No enum member matches '{input}'.\");","typeGuard":"static bool CanDehumanizeTo<TEnum>(string input) where TEnum : struct, Enum =>\n    input.DehumanizeTo<TEnum>(OnNoMatch.ReturnsNull) is not null;","tryCatchPattern":"try { return input.DehumanizeTo<MyEnum>(); }\ncatch (NoMatchFoundException) { return NotFound(); }","preventionTips":["Use the OnNoMatch.ReturnsNull overload for any input that is not guaranteed valid.","Do not pass user text straight to the throwing overload.","Remember matching is case-insensitive but does NOT trim whitespace, so normalize input first."],"tags":["enum","dehumanize","parsing","no-match"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}