dotnet/wpf · error · ArgumentException
SR.FixedDocumentExpectsDependencyObject
Error message
SR.FixedDocumentExpectsDependencyObject
What it means
FixedDocument.GetObjectPosition throws ArgumentException with SR.FixedDocumentExpectsDependencyObject when the object passed to it is not a DependencyObject. Because WPF document content elements (PageContent, FixedPage, etc.) are DependencyObjects, the API refuses any plain CLR object that cannot participate in the dependency property system.
Solutions
- Pass the actual DependencyObject document element (e.g. PageContent containing the FixedPage) rather than the underlying data object.
- Guard before calling: if (!(o is DependencyObject)) resolve the corresponding element first.
- If you hold a data item, map it to its content element (e.g. via ItemsControl.ItemContainerGenerator-style lookup) before querying the position.
Example fix
// before
object position = fixedDocument.GetObjectPosition(myDataItem);
// after
if (myDataItem is DependencyObject element)
{
object position = fixedDocument.GetObjectPosition(element);
} Defensive patterns
Strategy: type-guard
Validate before calling
bool isDependencyObject = o is System.Windows.DependencyObject;
Type guard
static bool IsDependencyObject(object o) => o is System.Windows.DependencyObject;
Try / catch
try
{
var position = fixedDocument.GetObjectPosition(element);
}
catch (ArgumentException ex)
{
logger.LogWarning(ex, "GetObjectPosition requires a DependencyObject; got {Type}.", element?.GetType().Name);
} Prevention
- Pass WPF document elements (PageContent/FixedPage), not view-model or data objects.
- Map data items to their corresponding content elements before calling position APIs.
- Enable analyzer/runtime checks that catch non-DependencyObject usage early in document code.
When it happens
Trigger: Calling GetObjectPosition (the inverse of GetContentPositionForElement) with a POCO, a string, or a non-WPF object instead of a document element such as PageContent or FixedPage.
Common situations: Passing view-model or data items instead of the actual visual/document elements; passing content loaded from a non-WPF pipeline; null-checking was fine but the object's type was wrong.
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.Format(SR.CannotConvertType, obj.GetType()…
- SR.Format(SR.CannotConvertType, obj.GetType()…
- SR.IDPInvalidContentPosition
- ' ' is not a Visual or Visual3D.
- 0x80070057
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a0e00da9cdac4d39.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs:444
asyncRequest.Cancelled = true;
asyncRequest.PageContent.GetPageRootAsyncCancel();
}
}
}
/// <summary>
/// <see cref="DynamicDocumentPaginator.GetObjectPosition"/>
/// </summary>
/// <exception cref="ArgumentNullException">element is NULL.</exception>
internal ContentPosition GetObjectPosition(Object o)
{
ArgumentNullException.ThrowIfNull(o);
DependencyObject element = o as DependencyObject;
if (element == null)
{
throw new ArgumentException(SR.FixedDocumentExpectsDependencyObject);
}
DocumentsTrace.FixedFormat.IDF.Trace($"IDF.GetContentPositionForElement({element})");
// Make sure that the call is in the right context.
// Dispatcher.VerifyAccess();
// walk up the logical parent chain to find the containing page
FixedPage fixedPage = null;
int pageIndex = -1;
if (element != this)
{
DependencyObject el = element;
while (el != null)
{
fixedPage = el as FixedPage;
if (fixedPage != null)
{View on GitHub (pinned to 81131a70a4)