{"record":{"id":"f9765b0872174496","repo":"dotnet/wpf","slug":"sr-invalidanchorposition","errorCode":null,"errorMessage":"SR.InvalidAnchorPosition","messagePattern":"SR\\.InvalidAnchorPosition","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs","lineNumber":1008,"sourceCode":"                // we need to mirror ourselves.  This is work around an issue with DocumentViewerBase which mirrors its\n                // contents (because its generated always as LeftToRight).  We are anchored to that content so the mirror\n                // gets applied to as as well.  This is our attempt to cancel out that mirror.\n                if (this.IsExpanded\n                    && this.FlowDirection == FlowDirection.RightToLeft\n                    && _attachedAnnotation.Parent is DocumentPageHost)\n                {\n                    _selfMirroring = true;\n                }\n                else\n                {\n                    _selfMirroring = false;\n                }\n\n                Point anchor = _attachedAnnotation.AnchorPoint;\n\n                if (double.IsInfinity(anchor.X) || double.IsInfinity(anchor.Y))\n                {\n                    throw new InvalidOperationException(SR.InvalidAnchorPosition);\n                }\n\n                if ((double.IsNaN(anchor.X)) || (double.IsNaN(anchor.Y)))\n                    return null;\n\n                GeneralTransformGroup transformations = new GeneralTransformGroup();\n\n                // We should be in normal Right-To-Left mode, but because of special cases\n                // in DocumentPageView, we've been mirrored.  We detect this and re-mirror\n                // ourselves.  We also need to do special handling of move/resize operations.\n                if (_selfMirroring)\n                {\n                    // This is the mirroring transform that will get the StickyNote to lay out\n                    // as if it were in Right-To-Left mode\n                    transformations.Children.Add(new MatrixTransform(-1.0, 0.0, 0.0, 1.0, this.Width, 0.0));\n                }\n\n                transformations.Children.Add(new TranslateTransform(anchor.X, anchor.Y));","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs#L990-L1026","documentation":"StickyNoteControl.GetDesiredTransform (IAnnotationComponent) computes a transform from the attached annotation's AnchorPoint; if the anchor coordinates are infinite (non-finite layout result), the transform cannot be computed and it throws InvalidOperationException('InvalidAnchorPosition'). Anchor points of NaN are tolerated (returns null, no transform) but Infinity is treated as a layout failure.","triggerScenarios":"An IAttachedAnnotation whose AnchorPoint is double.PositiveInfinity or double.NegativeInfinity in either coordinate during transform computation, typically produced by degenerate anchors from broken document layout or anchor segments resolving to empty rectangles.","commonSituations":"Annotations attached to content whose anchor was invalidated by scrolling/pagination, annotation files edited externally with bogus anchor points, rendering annotations while layout has not produced finite positions.","solutions":["Verify/repair the annotation's anchor data in the annotation store; delete and recreate the annotation if the anchor is corrupt.","Ensure the annotation's anchor components are resolved to finite rectangles before StickyNote renders (force layout / refresh AnnotationService).","Guard rendering code: remove or skip annotations whose AnchorPoint is non-finite before adding them to the service.","Catch InvalidOperationException during annotation rendering and fall back to re-creating the annotation."],"exampleFix":"// before\ncomponent.GetDesiredTransform(anchor); // throws on Infinity\n// after\nif (!double.IsInfinity(anchor.AnchorPoint.X) && !double.IsInfinity(anchor.AnchorPoint.Y))\n    component.GetDesiredTransform(anchor);","handlingStrategy":"validation","validationCode":"bool anchorValid = !double.IsInfinity(attachedAnnotation.AnchorPoint.X) && !double.IsInfinity(attachedAnnotation.AnchorPoint.Y);","typeGuard":"static bool HasFiniteAnchor(IAttachedAnnotation aa) =>\n    aa != null && !double.IsInfinity(aa.AnchorPoint.X) && !double.IsInfinity(aa.AnchorPoint.Y);","tryCatchPattern":"try { var t = component.GetDesiredTransform(target); }\ncatch (InvalidOperationException) { /* recreate annotation: anchor is corrupt */ }","preventionTips":["Recreate annotations whose anchor resolves to infinite coordinates.","Ensure layout has completed and anchors resolve to finite rectangles before rendering.","Sanitize externally supplied annotation files with bogus anchor points."],"tags":["wpf","annotations","layout"],"backgroundTag":"invalid-argument-value","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"}