dotnet/wpf · error · ArgumentException
SR.BadFixedTextPosition
Error message
SR.BadFixedTextPosition
What it means
FixedTextContainer.VerifyPosition also requires the ITextPointer to be a FixedTextPointer (the container's concrete pointer type). Passing a valid ITextPointer from another implementation throws ArgumentException(SR.BadFixedTextPosition) because only FixedTextPointer instances can be used with this container.
Solutions
- Create pointers via the FixedTextContainer (CreatePointerAtOffset/CreateStaticPointer) instead of other text stacks.
- Cast/convert the argument to FixedTextPointer within the owning container before use.
- Add an assertion/guard that the pointer type matches before calling.
- Catch ArgumentException and fall back to creating a container-native pointer.
Example fix
// before ITextPointer p = flowDoc.ContentStart; // wrong implementation fixedContainer.VerifyPosition(p); // throws // after FixedTextPointer p = fixedContainer.CreatePointerAtOffset(0, LogicalDirection.Forward); fixedContainer.VerifyPosition(p);
Defensive patterns
Strategy: type-guard
Validate before calling
bool IsFixedPointer(ITextPointer p) => p is FixedTextPointer;
Type guard
FixedTextPointer AsFixedPointer(ITextPointer p) => p as FixedTextPointer; // null check before use
Try / catch
try { container.VerifyPosition(pointer); }
catch (ArgumentException) { pointer = container.CreatePointerAtOffset(offset, direction); } Prevention
- Program against the concrete FixedTextPointer when working with fixed documents.
- Avoid mixing FlowDocument and FixedDocument pointer types.
- Add debug assertions checking pointer type at API boundaries.
When it happens
Trigger: Calling a FixedTextContainer API with an ITextPointer implemented by another text stack (e.g. a FlowDocument's TextPointer or a custom ITextPointer).
Common situations: Code written against ITextContainer/ITextPointer abstractions that mixes FlowDocument and FixedDocument pointers; unit tests passing mock pointers; refactoring that changed pointer types.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- SR.BadDistance
- SR.Collection_BadType
- SR.Format(SR.Animation_AnimationTimelineTypeMismatch…
- SR.Format(SR.Animation_AnimationTimelineTypeMismatch…
- SR.Format(SR.BadFixedTextPosition, "position")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/379597b320abf59f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextContainer.cs:320
#region Internal Methods
//--------------------------------------------------------------------
// Utility Method
//---------------------------------------------------------------------
internal FixedTextPointer VerifyPosition(ITextPointer position)
{
ArgumentNullException.ThrowIfNull(position);
if (position.TextContainer != this)
{
throw new ArgumentException(SR.Format(SR.NotInAssociatedContainer, "position"));
}
FixedTextPointer ftp = position as FixedTextPointer;
if (ftp == null)
{
throw new ArgumentException(SR.Format(SR.BadFixedTextPosition, "position"));
}
return ftp;
}
internal int GetPageNumber(ITextPointer textPointer)
{
FixedTextPointer fixedTextPointer = textPointer as FixedTextPointer;
int pageNumber = int.MaxValue;
if (fixedTextPointer != null)
{
if (fixedTextPointer.CompareTo(((ITextContainer)this).Start) == 0)
{
pageNumber = 0;
}
else if (fixedTextPointer.CompareTo(((ITextContainer)this).End) == 0)View on GitHub (pinned to 81131a70a4)