dotnet/wpf · error · InvalidOperationException
SR.NoElementObject
Error message
SR.NoElementObject
What it means
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.
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.
Example fix
// before
var value = pointer.ReadLocalValue(MyProperty); // may throw at non-text positions
// after
if (IsInsideTextElement(pointer)) { var value = pointer.ReadLocalValue(MyProperty); } Defensive patterns
Strategy: try-catch
Validate before calling
// No public pre-check; guard by only calling ReadLocalValue on pointers known to sit within a text element. bool isTextElementScoped = /* your position bookkeeping */;
Try / catch
try { value = pointer.ReadLocalValue(property); }
catch (InvalidOperationException) { value = DependencyProperty.UnsetValue; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- SR.TextPositionIsFrozen
- SR.BadDistance
- SR.Format(SR.TextSchema_CannotSplitElement…
- SR.NotInAssociatedContainer
- SR.RowCacheCannotModifyNonExistentLayout
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c60e267058b017b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextPointer.cs:209
{
ArgumentNullException.ThrowIfNull(property);
FixedElement e = _flowPosition.GetScopingElement();
return e.GetValue(property);
}
/// <summary>
/// <see cref="ITextPointer.ReadLocalValue"/>
/// </summary>
/// <remarks>Throws InvalidOperationException if there is no scoping element</remarks>
object ITextPointer.ReadLocalValue(DependencyProperty property)
{
ArgumentNullException.ThrowIfNull(property);
FixedElement e = _flowPosition.GetScopingElement();
if (!e.IsTextElement)
{
throw new InvalidOperationException(SR.NoElementObject);
}
return e.ReadLocalValue(property);
}
/// <summary>
/// <see cref="ITextPointer.GetLocalValueEnumerator"/>
/// </summary>
/// <remarks>Returns an empty enumerator if there is no scoping element</remarks>
LocalValueEnumerator ITextPointer.GetLocalValueEnumerator()
{
FixedElement e = _flowPosition.GetScopingElement();
if (!e.IsTextElement)
{
return (new DependencyObject()).GetLocalValueEnumerator();
}
View on GitHub (pinned to 81131a70a4)