{"record":{"id":"f692b54bf9e23cef","repo":"Humanizr/Humanizer","slug":"value-is-not-in-the-correct-format","errorCode":null,"errorMessage":"Value is not in the correct format","messagePattern":"Value is not in the correct format","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteSize.cs","lineNumber":1543,"sourceCode":"    /// For <see cref=\"ByteSizeUnitSystem.DecimalSi\"/> and <see cref=\"ByteSizeUnitSystem.BinaryIec\"/>, SI/IEC-prefixed\n    /// unit tokens are matched case-insensitively, while <c>b</c> and <c>B</c> remain case-sensitive.\n    /// Legacy parsing preserves the established behavior.\n    /// </remarks>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"s\"/> is <see langword=\"null\"/>.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"unitSystem\"/> is not defined.</exception>\n    /// <exception cref=\"FormatException\"><paramref name=\"s\"/> is not valid for the selected unit system.</exception>\n    public static ByteSize ParseWithUnitSystem(\n        string s,\n        ByteSizeUnitSystem unitSystem,\n        IFormatProvider? formatProvider = null)\n    {\n        ArgumentNullException.ThrowIfNull(s);\n        if (TryParseSpanWithUnitSystem(s.AsSpan(), unitSystem, formatProvider, out var result))\n        {\n            return result;\n        }\n\n        throw new FormatException(\"Value is not in the correct format\");\n    }\n\n    /// <summary>\n    /// Attempts to parse a byte size using only the tokens defined by the selected unit system.\n    /// </summary>\n    /// <param name=\"s\">The text to parse.</param>\n    /// <param name=\"unitSystem\">The unit system whose tokens are accepted.</param>\n    /// <param name=\"result\">\n    /// When this method returns, contains the parsed byte size if parsing succeeded; otherwise, the default value.\n    /// </param>\n    /// <returns><see langword=\"true\"/> if parsing succeeded; otherwise, <see langword=\"false\"/>.</returns>\n    /// <remarks>\n    /// For <see cref=\"ByteSizeUnitSystem.DecimalSi\"/> and <see cref=\"ByteSizeUnitSystem.BinaryIec\"/>, SI/IEC-prefixed\n    /// unit tokens are matched case-insensitively, while <c>b</c> and <c>B</c> remain case-sensitive.\n    /// Legacy parsing preserves the established behavior.\n    /// </remarks>\n    /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"unitSystem\"/> is not defined.</exception>\n    public static bool TryParseWithUnitSystem(","sourceCodeStart":1525,"sourceCodeEnd":1561,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteSize.cs#L1525-L1561","documentation":"Thrown by ByteSize.ParseWithUnitSystem when TryParseSpanWithUnitSystem returns false for the supplied text under the chosen unit system. ParseWithUnitSystem is the throwing wrapper over the Try variant; the FormatException signals that the input did not match the grammar or unit tokens of that system.","triggerScenarios":"Calling ParseWithUnitSystem(\"1234 XYZ\", ByteSizeUnitSystem.DecimalSi) where XYZ is not a recognized decimal token, or passing a binary 'GiB' token to a DecimalSi parse, or supplying text that has no parseable number. Empty/whitespace strings and stray symbols also fail.","commonSituations":"Parsing user-typed capacity strings, ingesting localized values whose decimal separator does not match the supplied formatProvider, or unit-system mismatches where the source data uses one convention but the parser is locked to the other.","solutions":["Prefer TryParseWithUnitSystem and report a friendly validation error on false rather than letting Parse throw.","Confirm the unit token in the input belongs to the selected system (decimal vs binary) before parsing.","Supply a formatProvider whose NumberDecimalSeparator matches the input's locale."],"exampleFix":"// before\nvar size = ByteSize.ParseWithUnitSystem(input, ByteSizeUnitSystem.DecimalSi);\n\n// after\nif (!ByteSize.TryParseWithUnitSystem(input, ByteSizeUnitSystem.DecimalSi, out var size))\n{\n    ModelState.AddModelError(nameof(input), \"Enter a value like '1.5 GB' using decimal SI units.\");\n    return;\n}","handlingStrategy":"validation","validationCode":"if (!ByteSize.TryParseWithUnitSystem(input, system, out var size))\n    throw new FormatException($\"Cannot parse '{input}' with the selected unit system.\");","typeGuard":null,"tryCatchPattern":"try { return ByteSize.ParseWithUnitSystem(input, system); }\ncatch (FormatException) { return null; }","preventionTips":["Use TryParseWithUnitSystem at trust boundaries","Match the unit token to the selected system","Supply a formatProvider whose separators match the input"],"tags":["bytesize","parsing","unit-system","formatexception"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}