{"record":{"id":"b72580090ed28ea0","repo":"dotnet/wpf","slug":"message-formatted-ls-error-message-e-g-sr-settabsfailure","errorCode":null,"errorMessage":"message (formatted LS error message, e.g. SR.SetTabsFailure + lserr)","messagePattern":"message \\(formatted LS error message, e\\.g\\. SR\\.SetTabsFailure \\+ lserr\\)","errorType":"exception","errorClass":"OutOfMemoryException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextFormatterContext.cs","lineNumber":391,"sourceCode":"            Invariant.Assert(_ploc != System.IntPtr.Zero);\n            LsErr lserr = UnsafeNativeMethods.LoSetTabs(\n                _ploc,\n                incrementalTab,\n                tabStopCount,\n                tabStops\n                );\n\n            if(lserr != LsErr.None)\n            {\n                ThrowExceptionFromLsError(SR.Format(SR.SetTabsFailure, lserr), lserr);\n            }\n        }\n\n\n        internal static void ThrowExceptionFromLsError(string message, LsErr lserr)\n        {\n            if (lserr == LsErr.OutOfMemory)\n                throw new OutOfMemoryException (message);\n\n            throw new Exception(message);\n        }\n\n\n        internal static bool IsSpecialCharacter(char c)\n        {\n            return _specialCharacters.ContainsKey(c);\n        }\n\n        private static void SetSpecialCharacters(ref LsContextInfo contextInfo)\n        {\n            Dictionary<char,bool> dict = new Dictionary<char,bool>();\n\n            /* The first three char fields do not designate special characters\n            dict[contextInfo.wchUndef] = true;\n            dict[contextInfo.wchNull] = true;\n            dict[contextInfo.wchSpace] = true;","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextFormatterContext.cs#L373-L409","documentation":"TextFormatterContext.ThrowExceptionFromLsError converts a native line-services (LS) error code into a managed exception: OutOfMemory becomes OutOfMemoryException, anything else becomes a plain Exception carrying the formatted LS error message. Callers like Init, SetBreaking, SetDoc, and SetTabs pass an LS error code when the unmanaged line-layout engine rejects an operation. It signals a failure inside the low-level text shaping/breaking engine rather than a caller-side misuse.","triggerScenarios":"Any TextFormatterImp operation where the underlying LS engine (CreateLine, AddTextRun, SetTabs, etc.) returns a non-None LsErr, e.g. internal line-layout failure or native out-of-memory during formatting.","commonSituations":"Formatting extremely large or corrupt text payloads exhausting memory, passing runs/properties the LS engine cannot handle, or native component state corruption mid-layout.","solutions":["Check the appended lserr value in the message to identify the specific native failure","Retry on a smaller text chunk to rule out resource exhaustion","Ensure text source is not modified between format passes (TextSource consistency)","If reproducible, capture the lserr and report; most LS errors are internal-invariant issues"],"exampleFix":"try { formatter.FormatLine(...) } catch (Exception ex) when (ex.Message.Contains(\"lserr\")) { /* inspect lserr, retry or log native failure */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { formatter.FormatLine(...); } catch (Exception ex) when (ex is OutOfMemoryException || ex.Message.Contains(\"lserr\")) { logNativeFailure(ex); }","preventionTips":["Keep TextSource stable across format passes","Avoid formatting pathologically large text in one pass","Log lserr codes for support when reproducible"],"tags":["wpf","textformatting","native-interop","linelayout"],"backgroundTag":"internal-invariant-violation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}