microsoft/ailab · error · InvalidOperationException

invalid MagnifierPosition

Error message

invalid MagnifierPosition

What it means

ImageCaptureWindow positions a magnifier overlay from a MagnifierPosition enum via a switch; when the supplied position value does not match any handled case (UpperLeft, UpperRight, LowerRight, ...), the computed left/top coordinates are indeterminate, so the code throws this sentinel error. It fires only when an unhandled enum member is passed — a bug in the magnifier positioning logic, not user input.

Solutions

  1. Add a default case to the switch that throws ArgumentOutOfRangeException with the actual value for better diagnostics
  2. Verify MagnifierPosition is set only from known UI locations (e.g. corners around the cursor)
  3. If a new enum member was added, implement its left/top computation in this switch
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at Snip-Insights/SnipInsight/ImageCapture/ImageCaptureWindow.xaml.cs:352 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/ailab@89fe2fc620 (2026-09-13). Data as JSON: /api/errors/868ff9bf6ae5d2bf. Report an issue: GitHub.

Appendix: source

Thrown at Snip-Insights/SnipInsight/ImageCapture/ImageCaptureWindow.xaml.cs:352

                    break;
                case MagnifierPosition.UpperLeft:
                    left = p.X - MagnifierWidth;
                    top = p.Y - MagnifierHeight;
                    break;
                case MagnifierPosition.UpperRight:
                    left = p.X + MagnifierHorizonSpace;
                    top = p.Y - MagnifierHeight;
                    break;
                case MagnifierPosition.LowerRight:
                    left = p.X + MagnifierHorizonSpace;
                    top = p.Y + MagnifierVerticalSpace;
                    break;
                case MagnifierPosition.Center:
                    left = p.X - MagnifierRadius;
                    top = p.Y - MagnifierRadius;
                    break;
                default:
                    throw new InvalidOperationException("invalid MagnifierPosition");
            }

            MagnifierTransform.X = left;
            MagnifierTransform.Y = top;
            MagnifierScale.CenterX = p.X;
            MagnifierScale.CenterY = p.Y;
            MagnifierScale.ScaleX = monitorScalingX;
            MagnifierScale.ScaleY = monitorScalingY;
        }
#endregion
    }
}

View on GitHub (pinned to 89fe2fc620)