dotnet/wpf · error · InvalidOperationException

SR.ColorConvertedBitmapExtensionNoSourceImage

Error message

SR.ColorConvertedBitmapExtensionNoSourceImage

What it means

ColorConvertedBitmapExtension.ProvideValue cannot build a color-converted bitmap without a source image. If the _image value was never set (no first constructor argument / Source property), it throws InvalidOperationException (SR.ColorConvertedBitmapExtensionNoSourceImage).

Solutions

  1. Pass a valid source image as the first argument: {ColorConvertedBitmap myImage, src.icm, dst.icm}
  2. Ensure the referenced resource/binding actually resolves to a non-null BitmapSource before the extension is evaluated
  3. Validate the XAML for missing extension arguments

Example fix

// before
<Image Source="{ColorConvertedBitmap {x:Null}, sRGB.icm, AdobeRGB.icm}" />
// after
<Image Source="{ColorConvertedBitmap {StaticResource Photo}, sRGB.icm, AdobeRGB.icm}" />
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(sourceImagePath))
    throw new ArgumentException("Source image is required by ColorConvertedBitmap.");

Type guard

static bool HasSourceImage(ColorConvertedBitmapExtension ext) => ext?.Source != null;

Try / catch

try { var bmp = (BitmapSource)ext.ProvideValue(sp); }
catch (InvalidOperationException ex) when (ex.Message.Contains("source image")) { /* supply Source */ }

Prevention

When it happens

Trigger: Using {ColorConvertedBitmap} markup extension without the required source image argument, or with a null image, then evaluating ProvideValue.

Common situations: XAML where the image path was deleted or the binding failed to produce a value; a resource returning null that was passed as the first argument.

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/4c459dd680bb95fc. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs:77

                        throw new InvalidOperationException(SR.ColorConvertedBitmapExtensionSyntax);
                    }
                }
            }
        }
        
        /// <summary>
        ///  Return an object that should be set on the targetObject's targetProperty
        ///  for this markup extension.  For ColorConvertedBitmapExtension, this is the object found in
        ///  a resource dictionary in the current parent chain that is keyed by ResourceKey
        /// </summary>
        /// <returns>
        ///  The object to set on this property.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (_image == null)
            {
                throw new InvalidOperationException(SR.ColorConvertedBitmapExtensionNoSourceImage);
            }
            if (_sourceProfile == null)
            {
                throw new InvalidOperationException(SR.ColorConvertedBitmapExtensionNoSourceProfile);
            }
            
            // [BreakingChange] 
            // (NullReferenceException in ColorConvertedBitmapExtension.ProvideValue)
            // We really should throw an ArgumentNullException here for serviceProvider.

            // Save away the BaseUri.
            IUriContext uriContext = serviceProvider.GetService(typeof(IUriContext)) as IUriContext;
            if( uriContext == null )
            {
                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, "IUriContext" ));
            }
            _baseUri = uriContext.BaseUri;
            

View on GitHub (pinned to 81131a70a4)