dotnet/wpf · error · InvalidOperationException

SR.Image_NoArgument (Source)

Error message

SR.Image_NoArgument (Source)

What it means

TransformedBitmap.IsValidForFinalizeCreation runs during EndInit to verify the bitmap was fully initialized: Source must be non-null and the Transform must be set and orthogonal. If Source is null and throwIfInvalid is true (the normal EndInit path), it throws InvalidOperationException with SR.Image_NoArgument("Source").

Solutions

  1. Assign Source (and Transform) between BeginInit and EndInit before calling EndInit
  2. Reorder initialization so EndInit is the last statement
  3. Guard the call: if (bitmap.Source != null) bitmap.EndInit(); otherwise defer or supply a default source

Example fix

// before
var tb = new TransformedBitmap();
tb.BeginInit();
tb.Transform = new RotateTransform(90);
tb.EndInit(); // throws: Source not set
// after
var tb = new TransformedBitmap();
tb.BeginInit();
tb.Source = source;
tb.Transform = new RotateTransform(90);
tb.EndInit();
Defensive patterns

Strategy: validation

Validate before calling

if (bitmap.Source == null)
    throw new InvalidOperationException("Assign Source before calling EndInit");

Try / catch

try { bitmap.EndInit(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Source"))
{ /* assign Source (and Transform), then retry EndInit */ }

Prevention

When it happens

Trigger: Calling EndInit() on a TransformedBitmap after BeginInit() without assigning Source — e.g. the Source binding failed, assignment was skipped by an earlier exception, or EndInit was called out of order.

Common situations: Deferred/XAML-style initialization where the Source binding resolves after EndInit; manually constructed bitmaps where EndInit precedes property assignment; async decode pipelines that delay setting Source.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/TransformedBitmap.cs:277

        /// </summary>
        private void SourcePropertyChangedHook(DependencyPropertyChangedEventArgs e)
        {
            if (!e.IsASubPropertyChange)
            {
                BitmapSource newSource = e.NewValue as BitmapSource;
                _source = newSource;
                RegisterDownloadEventSource(_source);
                _syncObject = (newSource != null) ? newSource.SyncObject : _bitmapInit;
            }
        }

        internal override bool IsValidForFinalizeCreation(bool throwIfInvalid)
        {
            if (Source == null)
            {
                if (throwIfInvalid)
                {
                    throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, "Source"));
                }
                return false;
            }

            Transform transform = Transform;
            if (transform == null)
            {
                if (throwIfInvalid)
                {
                    throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, "Transform"));
                }
                return false;
            }

            if (!CheckTransform(transform))
            {
                if (throwIfInvalid)
                {

View on GitHub (pinned to 81131a70a4)