dotnet/wpf · error · NotImplementedException

Not implemented.

Error message

Not implemented.

What it means

DocumentSequenceTextContainer implements ITextContainer for interop with the text editing stack, but char-offset-based pointer creation is not meaningful for a document sequence (which composes multiple child documents). The explicit interface implementation CreatePointerAtCharOffset unconditionally throws NotImplementedException.

Solutions

  1. Do not call CreatePointerAtCharOffset on DocumentSequenceTextContainer; use CreatePointerAtPosition or pointer-based navigation instead
  2. Obtain a pointer via the container's Start/End properties and move relatively
  3. If char-offset logic is required, operate on the individual child document's TextContainer instead of the sequence's

Example fix

// before
var ptr = ((ITextContainer)seqTextContainer).CreatePointerAtCharOffset(offset, LogicalDirection.Forward);
// after
var ptr = ((ITextContainer)seqTextContainer).Start.CreatePointer(LogicalDirection.Forward);
ptr.MoveToPosition(targetPosition);
Defensive patterns

Strategy: type-guard

Validate before calling

if (((ITextContainer)container) is DocumentSequenceTextContainer)
    throw new NotSupportedException("CreatePointerAtCharOffset is not supported on document sequences");

Type guard

bool SupportsCharOffsetPointer(ITextContainer c) => c is not DocumentSequenceTextContainer;

Try / catch

try { ptr = ((ITextContainer)c).CreatePointerAtCharOffset(off, dir); }
catch (NotImplementedException) { ptr = ((ITextContainer)c).Start.CreatePointer(dir); }

Prevention

When it happens

Trigger: Calling ITextContainer.CreatePointerAtCharOffset on a DocumentSequenceTextContainer, e.g. via text editor or selection code that uses char-offset navigation across a FixedDocumentSequence.

Common situations: Text editing frameworks (TextEditor, selection services) attempting char-offset addressing on a DocumentSequence; custom code casting the container to ITextContainer and calling char-offset APIs.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/9541816a7285484d. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextContainer.cs:102

                if (this.Changed != null && !skipEvents)
                {
                    Changed(this, changes);
                }
            }
        }

        // Allocate a new ITextPointer at the specified offset.
        // Equivalent to this.Start.CreatePointer(offset), but does not
        // necessarily allocate this.Start.
        ITextPointer ITextContainer.CreatePointerAtOffset(int offset, LogicalDirection direction)
        {
            return ((ITextContainer)this).Start.CreatePointer(offset, direction);
        }

        // Not Implemented.
        ITextPointer ITextContainer.CreatePointerAtCharOffset(int charOffset, LogicalDirection direction)
        {
            throw new NotImplementedException();
        }

        ITextPointer ITextContainer.CreateDynamicTextPointer(StaticTextPointer position, LogicalDirection direction)
        {
            return ((ITextPointer)position.Handle0).CreatePointer(direction);
        }

        StaticTextPointer ITextContainer.CreateStaticPointerAtOffset(int offset)
        {
            return new StaticTextPointer(this, ((ITextContainer)this).CreatePointerAtOffset(offset, LogicalDirection.Forward));
        }

        TextPointerContext ITextContainer.GetPointerContext(StaticTextPointer pointer, LogicalDirection direction)
        {
            return ((ITextPointer)pointer.Handle0).GetPointerContext(direction);
        }

        int ITextContainer.GetOffsetToPosition(StaticTextPointer position1, StaticTextPointer position2)

View on GitHub (pinned to 81131a70a4)