dotnet/wpf · error · InvalidOperationException

SR.ColorConvertedBitmapExtensionNoSourceProfile

Error message

SR.ColorConvertedBitmapExtensionNoSourceProfile

What it means

ProvideValue requires a source color profile to perform the color conversion. When the extension has an image but no source profile (second argument never supplied), it throws InvalidOperationException (SR.ColorConvertedBitmapExtensionNoSourceProfile).

Solutions

  1. Supply the source profile: {ColorConvertedBitmap image, sourceProfile.icm, destinationProfile.icm}
  2. Set both SourceProfile and DestinationProfile properties explicitly when using property syntax
  3. Keep .icm profile resources in the project and reference them correctly

Example fix

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

Strategy: validation

Validate before calling

if (sourceProfilePath == null || destinationProfilePath == null)
    throw new ArgumentException("Both source and destination profiles are required.");

Type guard

static bool HasProfiles(ColorConvertedBitmapExtension ext) => ext?.SourceProfile != null && ext?.DestinationProfile != null;

Try / catch

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

Prevention

When it happens

Trigger: Using {ColorConvertedBitmap image} with only one argument, or setting Source but leaving SourceProfile null, then evaluating ProvideValue.

Common situations: Omitting the source profile assuming WPF will infer it; partial edits of XAML that dropped the second 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/d1452dda5ad3e585. Report an issue: GitHub.

Appendix: source

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

        }
        
        /// <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;
            

            Uri imageUri = GetResolvedUri(_image);
            Uri sourceProfileUri = GetResolvedUri(_sourceProfile);
            Uri destinationProfileUri = GetResolvedUri(_destinationProfile);

View on GitHub (pinned to 81131a70a4)