{"record":{"id":"14d0a6e2e08ec14c","repo":"JamesNK/Newtonsoft.Json","slug":"requested-value-0-was-not-found","errorCode":null,"errorMessage":"Requested value '{0}' was not found.","messagePattern":"Requested value '(.+?)' was not found\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/EnumUtils.cs","lineNumber":371,"sourceCode":"\n                // if no match found, attempt case insensitive search\n                if (matchingIndex == null)\n                {\n                    matchingIndex = MatchName(value, enumNames, resolvedNames, valueIndex, valueSubstringLength, StringComparison.OrdinalIgnoreCase);\n                }\n\n                if (matchingIndex == null)\n                {\n                    // still can't find a match\n                    // before we throw an error, check whether the entire string has a case insensitive match against resolve names\n                    matchingIndex = FindIndexByName(resolvedNames, value, 0, value.Length, StringComparison.OrdinalIgnoreCase);\n                    if (matchingIndex != null)\n                    {\n                        return Enum.ToObject(enumType, enumValues[matchingIndex.Value]);\n                    }\n\n                    // no match so error\n                    throw new ArgumentException(\"Requested value '{0}' was not found.\".FormatWith(CultureInfo.InvariantCulture, value));\n                }\n\n                result |= enumValues[matchingIndex.Value];\n\n                // Move our pointer to the ending index to go again.\n                valueIndex = endIndex + 1;\n            }\n\n            return Enum.ToObject(enumType, result);\n        }\n\n        private static int? MatchName(string value, string[] enumNames, string[] resolvedNames, int valueIndex, int valueSubstringLength, StringComparison comparison)\n        {\n            int? matchingIndex = FindIndexByName(resolvedNames, value, valueIndex, valueSubstringLength, comparison);\n            if (matchingIndex == null)\n            {\n                matchingIndex = FindIndexByName(enumNames, value, valueIndex, valueSubstringLength, comparison);\n            }","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/EnumUtils.cs#L353-L389","documentation":"ParseEnum (EnumUtils.cs:326-371) tries, in order: exact resolved-name match, case-insensitive whole-string match, and flag-by-flag composition. If after all attempts no enum member/combination resolves, it throws ArgumentException at EnumUtils.cs:371 reporting the requested value.","triggerScenarios":"An enum string that does not correspond to any defined member or valid flag combination — typo, removed/renamed member, or a value from a newer version of the enum.","commonSituations":"Version skew (producer emits a member the consumer's enum doesn't define); typos in JSON; unexpected values from third-party APIs; renamed enum members without [EnumMember] aliases.","solutions":["Correct the JSON value to a valid member name (respecting [EnumMember(Value=...)] and the naming strategy).","Add the missing member, or an [EnumMember(Value=\"...\")] alias mapping the external spelling to a member.","Register a JsonConverter that maps unknown enum values to a designated default/Unknown member.","For [Flags] enums, ensure the string is a comma-separated list of valid flag names."],"exampleFix":"// before: JSON \"status\": \"actve\" -> no match -> throws\n// after: fix spelling to \"active\", or add\n[EnumMember(Value = \"actve\")] Active,","handlingStrategy":"try-catch","validationCode":"// Pre-check the value resolves to a known member before parsing.\nvar known = Enum.GetNames(enumType).SelectMany(n => new[] { n }); // plus [EnumMember] values if present\nif (!known.Any(k => string.Equals(k, value, StringComparison.OrdinalIgnoreCase)))\n    return default; // or map to an Unknown member","typeGuard":"static bool IsKnownEnumValue(Type enumType, string value) => Enum.GetNames(enumType).Any(n => string.Equals(n, value, StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { return EnumUtils.ParseEnum(enumType, null, value, false); } catch (ArgumentException ex) when (ex.Message.Contains(\"was not found\")) { return default; }","preventionTips":["Add [EnumMember(Value=\"...\")] aliases for external spellings.","Register a JsonConverter that maps unknown values to a default/Unknown member.","Keep producer and consumer enum versions in sync.","For flags, ensure comma-separated strings list only valid flag names."],"tags":["enum","serialization","newtonsoft-json"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}