dotnet/wpf · error · ArgumentNullException

value

Error message

value

What it means

The PrintContext.JobTicket property setter throws ArgumentNullException with parameter name "value" when assigning null. A PrintTicket is required once exposed; setting it to null is rejected instead of clearing the ticket.

Solutions

  1. Only assign a valid PrintTicket instance; if you need 'no ticket', skip the assignment entirely (use the default ticket)
  2. Guard: if (ticket != null) context.JobTicket = ticket;
  3. Initialize the ticket via PrintDialog.PrintTicket or queue.DefaultPrintTicket so a valid object always exists

Example fix

// before
context.JobTicket = dialog.PrintTicket; // throws if null
// after
if (dialog.PrintTicket != null) context.JobTicket = dialog.PrintTicket;
Defensive patterns

Strategy: validation

Validate before calling

if (ticket == null) return; // skip assignment when no ticket is available

Type guard

bool HasTicket(PrintContext ctx) => ctx?.JobTicket != null;

Try / catch

try { context.JobTicket = ticket; }
catch (ArgumentNullException ex) when (ex.ParamName == "value") { /* fall back to queue.DefaultPrintTicket */ }

Prevention

When it happens

Trigger: printContext.JobTicket = null — e.g. clearing print settings, propagating a possibly-null ticket from PrintDialog.PrintTicket, or default-initializing the property.

Common situations: Print dialogs whose PrintTicket was never initialized; resetting user preferences; copying settings between contexts where one has no ticket.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs:272

            {
                _cancel = value;
            }
        }

        /// <summary>
        /// JobTicket property
        /// </summary>
        public JobTicket JobTicket
        {
            get
            {
                return _jobTicket;
            }
            set
            {
                if( value == null )
                {
                    throw new ArgumentNullException("value");
                }
                _jobTicket = value;
            }
        }

        private bool IsPremium()
        {
            if (_queue.IsDualHeaded)
            {
                return true;
            }

            // Temp solution to allow premium printing on normal print queue
            if ((_queue.Comment != null) && (_queue.Comment.Length >= 4))
            {
                return (_queue.Comment[0] == 'x') || (_queue.Comment[0] == 'e');
            }

View on GitHub (pinned to 81131a70a4)