{"record":{"id":"4c459dd680bb95fc","repo":"dotnet/wpf","slug":"sr-colorconvertedbitmapextensionnosourceimage","errorCode":null,"errorMessage":"SR.ColorConvertedBitmapExtensionNoSourceImage","messagePattern":"SR\\.ColorConvertedBitmapExtensionNoSourceImage","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs","lineNumber":77,"sourceCode":"                        throw new InvalidOperationException(SR.ColorConvertedBitmapExtensionSyntax);\n                    }\n                }\n            }\n        }\n        \n        /// <summary>\n        ///  Return an object that should be set on the targetObject's targetProperty\n        ///  for this markup extension.  For ColorConvertedBitmapExtension, this is the object found in\n        ///  a resource dictionary in the current parent chain that is keyed by ResourceKey\n        /// </summary>\n        /// <returns>\n        ///  The object to set on this property.\n        /// </returns>\n        public override object ProvideValue(IServiceProvider serviceProvider)\n        {\n            if (_image == null)\n            {\n                throw new InvalidOperationException(SR.ColorConvertedBitmapExtensionNoSourceImage);\n            }\n            if (_sourceProfile == null)\n            {\n                throw new InvalidOperationException(SR.ColorConvertedBitmapExtensionNoSourceProfile);\n            }\n            \n            // [BreakingChange] \n            // (NullReferenceException in ColorConvertedBitmapExtension.ProvideValue)\n            // We really should throw an ArgumentNullException here for serviceProvider.\n\n            // Save away the BaseUri.\n            IUriContext uriContext = serviceProvider.GetService(typeof(IUriContext)) as IUriContext;\n            if( uriContext == null )\n            {\n                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, \"IUriContext\" ));\n            }\n            _baseUri = uriContext.BaseUri;\n            ","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs#L59-L95","documentation":"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).","triggerScenarios":"Using {ColorConvertedBitmap} markup extension without the required source image argument, or with a null image, then evaluating ProvideValue.","commonSituations":"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.","solutions":["Pass a valid source image as the first argument: {ColorConvertedBitmap myImage, src.icm, dst.icm}","Ensure the referenced resource/binding actually resolves to a non-null BitmapSource before the extension is evaluated","Validate the XAML for missing extension arguments"],"exampleFix":"// before\n<Image Source=\"{ColorConvertedBitmap {x:Null}, sRGB.icm, AdobeRGB.icm}\" />\n// after\n<Image Source=\"{ColorConvertedBitmap {StaticResource Photo}, sRGB.icm, AdobeRGB.icm}\" />","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(sourceImagePath))\n    throw new ArgumentException(\"Source image is required by ColorConvertedBitmap.\");","typeGuard":"static bool HasSourceImage(ColorConvertedBitmapExtension ext) => ext?.Source != null;","tryCatchPattern":"try { var bmp = (BitmapSource)ext.ProvideValue(sp); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"source image\")) { /* supply Source */ }","preventionTips":["Always pass the image as the first extension argument","Verify the resource/binding feeding the image resolves before evaluation","Keep image Build Action = Resource so the path resolves"],"tags":["wpf","xaml","markup-extension","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}