dotnet/wpf · error · InvalidOperationException

parameter

Error message

parameter

What it means

PageCache.PaginationProgressDelegate is a DispatcherOperation callback that must receive a PaginationProgressEventArgs via its 'parameter' argument. If the parameter is null or of another type, the cast yields null and the method throws InvalidOperationException("parameter"). This is an internal invariant: only PageCache itself enqueues this delegate, so a violation means the internal work-item contract was broken.

Solutions

  1. Do not call PaginationProgressDelegate directly; let the pagination Dispatcher manage it.
  2. When invoking via reflection/tests, pass a correctly-typed PaginationProgressEventArgs instance.
  3. Apply current .NET Framework/WPF servicing updates if seen in stock scenarios.
  4. Capture which pagination event scheduled the operation to identify the producer.

Example fix

// before
object r = InvokeDelegate("PaginationProgressDelegate", null);

// after
var args = new PaginationProgressEventArgs(0, 1);
object r = InvokeDelegate("PaginationProgressDelegate", args);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(parameter is PaginationProgressEventArgs args))
    throw new InvalidOperationException("parameter");

Type guard

static bool IsValidProgressParam(object p) => p is PaginationProgressEventArgs;

Try / catch

try { result = del(parameter); }
catch (InvalidOperationException ex) when (ex.Message == "parameter") { LogInvalidDispatch(parameter); }

Prevention

When it happens

Trigger: The dispatcher operation queued by PageCache fires with a parameter that is not a PaginationProgressEventArgs (null or wrong type) — an internal enqueue bug, or reflection/test/custom code invoking PaginationProgressDelegate directly with an unexpected argument.

Common situations: Rare; seen when reflection or unit tests invoke PaginationProgressDelegate directly with a bad parameter, or in older .NET Framework builds with pagination dispatch bugs.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/PageCache.cs:338

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal,
                   new DispatcherOperationCallback(PaginationProgressDelegate), args);
        }

        /// <summary>
        /// Asynchronously handles the PaginationProgress event.
        /// This means that one or more pages have been added to the document, so we
        /// add any new pages to the cache, mark them as dirty, and fire off our PaginationProgress
        /// event.
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private object PaginationProgressDelegate(object parameter)
        {
            PaginationProgressEventArgs args = parameter as PaginationProgressEventArgs;

            if (args == null)
            {
                throw new InvalidOperationException("parameter");
            }

            //Validate incoming parameters.
            ValidatePaginationArgs(args.Start, args.Count);

            if (_isPaginationCompleted)
            {
                if (args.Start == 0)
                {
                    //Since we've started repaginating from the beginning of the document
                    //after pagination was completed, we can't assume we know
                    //the default page size anymore.
                    _isDefaultSizeKnown = false;
                    _dynamicPageSizes = false;
                }

                //Reset our IsPaginationCompleted flag since we just got a pagination event.
                _isPaginationCompleted = false;

View on GitHub (pinned to 81131a70a4)