dotnet/wpf · error

ArgumentOutOfRangeException(nameof(scale))

Error message

ArgumentOutOfRangeException(nameof(scale))

What it means

ArgumentOutOfRangeException from DocumentGrid.SetScale: the requested scale factor is <= 0 or not a valid double (NaN/infinite), which is nonsensical for a page zoom factor, so the parameter-validation helper rejects it before layout is invalidated.

Solutions

  1. Validate the scale is a finite positive value (e.g. clamp to a sensible zoom range like 0.1–5.0) before calling SetScale
  2. Guard against NaN from external input before computing the scale
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:427 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:427

        {
            //We just set the VerticalOffset to our document's extent.
            SetVerticalOffsetInternal(ExtentHeight);
        }

        /// <summary>
        /// Sets the scale factor applied to pages in the document, while
        /// keeping the "Active Focus" centered.
        /// </summary>
        /// <param name="scale"></param>
        public void SetScale(double scale)
        {
            if (!DoubleUtil.AreClose(scale, Scale))
            {
                ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(scale, 0.0);

                if (!Helper.IsDoubleValid(scale))
                {
                    throw new ArgumentOutOfRangeException(nameof(scale));
                }

                QueueSetScale(scale);
            }
        }

        /// <summary>
        /// Changes the view to the specified number of columns.
        /// </summary>
        /// <param name="columns"></param>
        public void SetColumns(int columns)
        {
            ArgumentOutOfRangeException.ThrowIfLessThan(columns, 1);

            //Perf Tracing - Mark Layout Change Start
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXPS, EventTrace.Event.WClientDRXLayoutBegin);

            QueueUpdateDocumentLayout(new DocumentLayout(columns, ViewMode.SetColumns));

View on GitHub (pinned to 81131a70a4)