dotnet/wpf · error · InvalidOperationException

SR.ColorConvertedBitmapExtensionSyntax

Error message

SR.ColorConvertedBitmapExtensionSyntax

What it means

ColorConvertedBitmapExtension is a markup extension that needs exactly one source color profile and one destination color profile. When ProvideValue/SetValueInput parses its arguments and a third profile string is supplied, it throws InvalidOperationException (SR.ColorConvertedBitmapExtensionSyntax) because the extension syntax allows at most two profile arguments.

Solutions

  1. Provide exactly: source image, source profile, destination profile — remove the extra argument
  2. Use named properties (Source/SourceProfile/DestinationProfile) on the extension instead of positional constructor args
  3. Validate the XAML with the designer/compiler before running

Example fix

// before
<Image Source="{ColorConvertedBitmap image.jpg, sRGB.icm, AdobeRGB.icm, extra.icm}" />
// after
<Image Source="{ColorConvertedBitmap image.jpg, sRGB.icm, AdobeRGB.icm}" />
Defensive patterns

Strategy: validation

Validate before calling

if (args != null && args.Length > 3)
    throw new ArgumentException("ColorConvertedBitmap takes at most image + 2 profiles.");

Type guard

static bool IsValidColorConvertedBitmapArgs(object[] a) => a != null && a.Length <= 3 && a[0] != null;

Try / catch

try { var bmp = (BitmapSource)ext.ProvideValue(sp); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ColorConvertedBitmap")) { /* fix XAML args */ }

Prevention

When it happens

Trigger: Passing more than two string arguments to the ColorConvertedBitmap markup extension, e.g. {ColorConvertedBitmap img, srcProfile, destProfile, extra}.

Common situations: Copy-paste errors in XAML that leave an extra profile argument; misunderstanding that the third positional argument is interpreted as another profile rather than something else.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

            foreach (string str in tokens)
            {
                if (str.Length > 0)
                {
                    if (_image == null)
                    {
                        _image = str;
                    }
                    else if (_sourceProfile == null)
                    {
                        _sourceProfile = str;
                    }
                    else if (_destinationProfile == null)
                    {
                        _destinationProfile = str;
                    }
                    else
                    {
                        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);

View on GitHub (pinned to 81131a70a4)