{"record":{"id":"909b1a03b3b86f73","repo":"dotnet/wpf","slug":"sr-hyphenatordisposed","errorCode":null,"errorMessage":"SR.HyphenatorDisposed","messagePattern":"SR\\.HyphenatorDisposed","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/NaturalLanguageHyphenator.cs","lineNumber":121,"sourceCode":"            CultureInfo     textCulture\n            )\n        {\n            Invariant.Assert(\n                    characterSource != null\n                &&  characterSource.Length > 0\n                &&  length > 0\n                &&  length <= characterSource.Length\n                );\n\n            if (_hyphenatorResource == IntPtr.Zero)\n            {\n                // No hyphenator available, no service delivered\n                return null;\n            }\n\n            if (_disposed)\n            {\n                throw new ObjectDisposedException(SR.HyphenatorDisposed);\n            }\n\n            byte[] isHyphenPositions = new byte[(length + 7) / 8];\n\n            UnsafeNativeMethods.NlHyphenate(\n                _hyphenatorResource,\n                characterSource,\n                length,\n                ((textCulture != null && textCulture != CultureInfo.InvariantCulture) ? textCulture.LCID : 0),\n                isHyphenPositions,\n                isHyphenPositions.Length\n                );\n\n            return new HyphenBreaks(isHyphenPositions, length);\n        }\n\n        /// <summary>\n        /// Private implementation of TextLexicalBreaks that encapsulates hyphen opportunities within","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/NaturalLanguageHyphenator.cs#L103-L139","documentation":"NaturalLanguageHyphenator.AnalyzeText throws ObjectDisposedException with SR.HyphenatorDisposed when the hyphenator's native resource has already been released via Dispose. Once disposed, the native NlHyphenate handle (_hyphenatorResource) is invalid, so the API refuses to run rather than corrupt memory or crash native code.","triggerScenarios":"Calling AnalyzeText on a hyphenator instance after Dispose() has been called on it; typically reusing a cached/static hyphenator whose Dispose ran during teardown or page unload while text layout still runs.","commonSituations":"Hyphenation enabled on a TextBox/FlowDocument while the owning document or control is being disposed on a background or layout thread; races where one component disposes the shared hyphenator while another still formats text.","solutions":["Stop using the hyphenator instance after calling Dispose; create a new NaturalLanguageHyphenator for subsequent analysis","Check the _disposed/IsDisposed state before calling AnalyzeText, or guard with try-catch for ObjectDisposedException","Fix disposal ordering so text layout/hyphenation finishes before the hyphenator is disposed"],"exampleFix":"// before\nhyphenator.Dispose();\nvar positions = hyphenator.AnalyzeText(text, length);\n// after\nvar positions = hyphenator.AnalyzeText(text, length);\nhyphenator.Dispose();","handlingStrategy":"try-catch","validationCode":"if (hyphenator == null) return null; // also avoid use after Dispose by tracking lifetime","typeGuard":"bool IsUsable(NaturalLanguageHyphenator h) => h != null && !h.IsDisposed;","tryCatchPattern":"try { return hyphenator.AnalyzeText(text, length); } catch (ObjectDisposedException) { return null; }","preventionTips":["Call Dispose only after all text layout work is complete","Do not share one hyphenator across disposing components","Re-create the hyphenator instead of reusing a disposed instance"],"tags":["wpf","object-disposed","hyphenation","text-layout"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}