{"record":{"id":"204b6d1397597002","repo":"abpframework/abp","slug":"len-argument-can-not-be-bigger-than-given-string-s","errorCode":null,"errorMessage":"len argument can not be bigger than given string's length!","messagePattern":"len argument can not be bigger than given string's length!","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs","lineNumber":75,"sourceCode":"    /// </summary>\n    [ContractAnnotation(\"str:null => true\")]\n    public static bool IsNullOrWhiteSpace([System.Diagnostics.CodeAnalysis.NotNullWhen(false)]this string? str)\n    {\n        return string.IsNullOrWhiteSpace(str);\n    }\n\n    /// <summary>\n    /// Gets a substring of a string from beginning of the string.\n    /// </summary>\n    /// <exception cref=\"ArgumentNullException\">Thrown if <paramref name=\"str\"/> is null</exception>\n    /// <exception cref=\"ArgumentException\">Thrown if <paramref name=\"len\"/> is bigger that string's length</exception>\n    public static string Left(this string str, int len)\n    {\n        Check.NotNull(str, nameof(str));\n\n        if (str.Length < len)\n        {\n            throw new ArgumentException(\"len argument can not be bigger than given string's length!\");\n        }\n\n        return str.Substring(0, len);\n    }\n\n    /// <summary>\n    /// Converts line endings in the string to <see cref=\"Environment.NewLine\"/>.\n    /// </summary>\n    public static string NormalizeLineEndings(this string str)\n    {\n        return str.Replace(\"\\r\\n\", \"\\n\").Replace(\"\\r\", \"\\n\").Replace(\"\\n\", Environment.NewLine);\n    }\n\n    /// <summary>\n    /// Gets index of nth occurrence of a char in a string.\n    /// </summary>\n    /// <param name=\"str\">source string to be searched</param>\n    /// <param name=\"c\">Char to search in <paramref name=\"str\"/></param>","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs#L57-L93","documentation":"Thrown by AbpStringExtensions.Left — the extension that takes the first len characters of a string. If len exceeds str.Length, no valid substring exists, so an ArgumentException is raised (after the null check via Check.NotNull). The same message text is shared with Right().","triggerScenarios":"Calling str.Left(len) where len > str.Length, e.g. \"abc\".Left(5). A negative len is handled by Substring's own ArgumentOutOfRangeException instead.","commonSituations":"Hard-coded length assumed larger than runtime input; off-by-one when computing a prefix length; calling Left on a possibly-empty string without checking length first.","solutions":["Guard the length before calling: if (len > str.Length) len = str.Length; or use Math.Min.","Validate input length upstream so the call site always receives a sufficiently long string.","Prefer str.Length checks or take(0, Math.Min(len, str.Length)) semantics if truncation is acceptable."],"exampleFix":"// before\nvar prefix = url.Left(10); // throws if url shorter than 10\n\n// after\nvar prefix = url.Left(Math.Min(10, url.Length));\n// or guard\nif (url.Length < 10) { /* handle short case */ }","handlingStrategy":"validation","validationCode":"// Clamp the length before calling Left\nvar safeLen = Math.Min(len, str.Length);\nvar prefix = str.Left(safeLen);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp len with Math.Min(len, str.Length) before calling Left.","Validate input string length upstream.","Prefer explicit length checks when truncation must be handled specially."],"tags":["string","extension-method","argument","abp-core"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}