{"record":{"id":"c60e267058b017b7","repo":"dotnet/wpf","slug":"sr-noelementobject","errorCode":null,"errorMessage":"SR.NoElementObject","messagePattern":"SR\\.NoElementObject","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextPointer.cs","lineNumber":209,"sourceCode":"        {\n            ArgumentNullException.ThrowIfNull(property);\n\n            FixedElement e = _flowPosition.GetScopingElement();\n            return e.GetValue(property);\n        }\n\n        /// <summary>\n        /// <see cref=\"ITextPointer.ReadLocalValue\"/>\n        /// </summary>\n        /// <remarks>Throws InvalidOperationException if there is no scoping element</remarks>\n        object ITextPointer.ReadLocalValue(DependencyProperty property)\n        {\n            ArgumentNullException.ThrowIfNull(property);\n\n            FixedElement e = _flowPosition.GetScopingElement();\n            if (!e.IsTextElement)\n            {\n                throw new InvalidOperationException(SR.NoElementObject);\n            }\n\n            return e.ReadLocalValue(property);\n        }\n\n        /// <summary>\n        /// <see cref=\"ITextPointer.GetLocalValueEnumerator\"/>\n        /// </summary>\n        /// <remarks>Returns an empty enumerator if there is no scoping element</remarks>\n        LocalValueEnumerator ITextPointer.GetLocalValueEnumerator()\n        {\n            FixedElement e = _flowPosition.GetScopingElement();\n\n            if (!e.IsTextElement)\n            {\n                return (new DependencyObject()).GetLocalValueEnumerator();\n            }\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextPointer.cs#L191-L227","documentation":"FixedTextPointer.ReadLocalValue requires the pointer to be scoped to a text element of the FixedElement tree. If the scoping element is not a text element (e.g. the pointer sits at a non-element position), an InvalidOperationException(SR.NoElementObject) is thrown because there is no element object to read a local value from.","triggerScenarios":"Calling ReadLocalValue on a FixedTextPointer whose FlowPosition's scoping element is not a text element — e.g. a pointer at the document root or positioned between structural elements.","commonSituations":"Using pointers created at document-level offsets rather than within a Glyphs/Paragraph text element; querying dependency property values on pointers after the element tree changed.","solutions":["Ensure the pointer is positioned inside a text element (e.g. use TextElement boundary positions) before calling ReadLocalValue.","Check the scoping element's IsTextElement via your own navigation logic before reading values.","Read the property from the FixedElement/page object directly instead of through the pointer.","Catch InvalidOperationException and treat the value as unset."],"exampleFix":"// before\nvar value = pointer.ReadLocalValue(MyProperty); // may throw at non-text positions\n// after\nif (IsInsideTextElement(pointer)) { var value = pointer.ReadLocalValue(MyProperty); }","handlingStrategy":"try-catch","validationCode":"// No public pre-check; guard by only calling ReadLocalValue on pointers known to sit within a text element.\nbool isTextElementScoped = /* your position bookkeeping */;","typeGuard":null,"tryCatchPattern":"try { value = pointer.ReadLocalValue(property); }\ncatch (InvalidOperationException) { value = DependencyProperty.UnsetValue; }","preventionTips":["Only read dependency properties from pointers inside text elements.","Navigate to the enclosing Glyphs/Paragraph element before querying values.","Avoid caching element-scoped pointers across document mutations."],"tags":["wpf","documents","invalid-operation","text-pointer"],"backgroundTag":"invalid-state-transition","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"}