{"record":{"id":"7f8fd2056fb4b1d9","repo":"JamesNK/Newtonsoft.Json","slug":"must-specify-valid-information-for-parsing-in-the","errorCode":null,"errorMessage":"Must specify valid information for parsing in the string.","messagePattern":"Must specify valid information for parsing in the string\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/EnumUtils.cs","lineNumber":292,"sourceCode":"            // first check if the entire text (including commas) matches a resolved name\n            int? matchingIndex = FindIndexByName(resolvedNames, value, 0, value.Length, StringComparison.Ordinal);\n            if (matchingIndex != null)\n            {\n                return Enum.ToObject(enumType, enumValues[matchingIndex.Value]);\n            }\n\n            int firstNonWhitespaceIndex = -1;\n            for (int i = 0; i < value.Length; i++)\n            {\n                if (!char.IsWhiteSpace(value[i]))\n                {\n                    firstNonWhitespaceIndex = i;\n                    break;\n                }\n            }\n            if (firstNonWhitespaceIndex == -1)\n            {\n                throw new ArgumentException(\"Must specify valid information for parsing in the string.\");\n            }\n\n            // check whether string is a number and parse as a number value\n            char firstNonWhitespaceChar = value[firstNonWhitespaceIndex];\n            if (char.IsDigit(firstNonWhitespaceChar) || firstNonWhitespaceChar == '-' || firstNonWhitespaceChar == '+')\n            {\n                Type underlyingType = Enum.GetUnderlyingType(enumType);\n\n                value = value.Trim();\n                object? temp = null;\n\n                try\n                {\n                    temp = Convert.ChangeType(value, underlyingType, CultureInfo.InvariantCulture);\n                }\n                catch (FormatException)\n                {\n                    // We need to Parse this as a String instead. There are cases","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/EnumUtils.cs#L274-L310","documentation":"ParseEnum (EnumUtils.cs:281-293) scans the input string for the first non-whitespace character to begin parsing. If the entire string is whitespace (firstNonWhitespaceIndex stays -1), it throws ArgumentException at EnumUtils.cs:292 — there is no content to parse into an enum value.","triggerScenarios":"An empty or all-whitespace string is supplied as an enum value — e.g. JSON `\"status\": \"   \"` for an enum field, or a value that was trimmed to empty.","commonSituations":"Whitespace-only enum strings in JSON payloads; upstream trimming producing empty values; default/missing fields represented as blank strings; integration with APIs that emit empty for unset.","solutions":["Validate the string with !string.IsNullOrWhiteSpace(value) before parsing.","Treat blank/empty as the enum's default value (or a designated 'Unknown' member) instead of calling ParseEnum.","Sanitize incoming JSON/string values at the boundary.","Use StringEnumConverter with a fallback for null/empty."],"exampleFix":"// before\nvar e = (MyEnum)Enum.Parse(typeof(MyEnum), s); // s = \"   \" -> throws\n// after\nif (string.IsNullOrWhiteSpace(s)) return default(MyEnum);\nvar e = (MyEnum)Enum.Parse(typeof(MyEnum), s.Trim());","handlingStrategy":"validation","validationCode":"// Reject blank strings before parsing an enum.\nif (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(\"Enum value must not be blank.\");\nvalue = value.Trim();","typeGuard":"static bool IsParsableEnumString(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { return EnumUtils.ParseEnum(enumType, null, value, false); } catch (ArgumentException ex) when (ex.Message.Contains(\"valid information for parsing\")) { return default; }","preventionTips":["Validate enum strings with !IsNullOrWhiteSpace before parsing.","Map blank/empty to a designated default member.","Sanitize incoming JSON values at the boundary."],"tags":["enum","validation","newtonsoft-json"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}