{"record":{"id":"beea90593a8da927","repo":"dotnet/wpf","slug":"sr-colorconvertedbitmapextensionsyntax","errorCode":null,"errorMessage":"SR.ColorConvertedBitmapExtensionSyntax","messagePattern":"SR\\.ColorConvertedBitmapExtensionSyntax","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs","lineNumber":59,"sourceCode":"            foreach (string str in tokens)\n            {\n                if (str.Length > 0)\n                {\n                    if (_image == null)\n                    {\n                        _image = str;\n                    }\n                    else if (_sourceProfile == null)\n                    {\n                        _sourceProfile = str;\n                    }\n                    else if (_destinationProfile == null)\n                    {\n                        _destinationProfile = str;\n                    }\n                    else\n                    {\n                        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);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs#L41-L77","documentation":"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.","triggerScenarios":"Passing more than two string arguments to the ColorConvertedBitmap markup extension, e.g. {ColorConvertedBitmap img, srcProfile, destProfile, extra}.","commonSituations":"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.","solutions":["Provide exactly: source image, source profile, destination profile — remove the extra argument","Use named properties (Source/SourceProfile/DestinationProfile) on the extension instead of positional constructor args","Validate the XAML with the designer/compiler before running"],"exampleFix":"// before\n<Image Source=\"{ColorConvertedBitmap image.jpg, sRGB.icm, AdobeRGB.icm, extra.icm}\" />\n// after\n<Image Source=\"{ColorConvertedBitmap image.jpg, sRGB.icm, AdobeRGB.icm}\" />","handlingStrategy":"validation","validationCode":"if (args != null && args.Length > 3)\n    throw new ArgumentException(\"ColorConvertedBitmap takes at most image + 2 profiles.\");","typeGuard":"static bool IsValidColorConvertedBitmapArgs(object[] a) => a != null && a.Length <= 3 && a[0] != null;","tryCatchPattern":"try { var bmp = (BitmapSource)ext.ProvideValue(sp); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ColorConvertedBitmap\")) { /* fix XAML args */ }","preventionTips":["Use exactly three arguments: image, source profile, destination profile","Prefer named properties over positional markup-extension arguments","Let the XAML designer validate the extension syntax"],"tags":["wpf","xaml","markup-extension","argument-count"],"backgroundTag":"invalid-argument-format","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"}