{"record":{"id":"d1452dda5ad3e585","repo":"dotnet/wpf","slug":"sr-colorconvertedbitmapextensionnosourceprofile","errorCode":null,"errorMessage":"SR.ColorConvertedBitmapExtensionNoSourceProfile","messagePattern":"SR\\.ColorConvertedBitmapExtensionNoSourceProfile","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs","lineNumber":81,"sourceCode":"        }\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            \n\n            Uri imageUri = GetResolvedUri(_image);\n            Uri sourceProfileUri = GetResolvedUri(_sourceProfile);\n            Uri destinationProfileUri = GetResolvedUri(_destinationProfile);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ColorConvertedBitmapExtension.cs#L63-L99","documentation":"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).","triggerScenarios":"Using {ColorConvertedBitmap image} with only one argument, or setting Source but leaving SourceProfile null, then evaluating ProvideValue.","commonSituations":"Omitting the source profile assuming WPF will infer it; partial edits of XAML that dropped the second argument.","solutions":["Supply the source profile: {ColorConvertedBitmap image, sourceProfile.icm, destinationProfile.icm}","Set both SourceProfile and DestinationProfile properties explicitly when using property syntax","Keep .icm profile resources in the project and reference them correctly"],"exampleFix":"// before\n<Image Source=\"{ColorConvertedBitmap image.jpg, AdobeRGB.icm}\" />\n// after\n<Image Source=\"{ColorConvertedBitmap image.jpg, sRGB.icm, AdobeRGB.icm}\" />","handlingStrategy":"validation","validationCode":"if (sourceProfilePath == null || destinationProfilePath == null)\n    throw new ArgumentException(\"Both source and destination profiles are required.\");","typeGuard":"static bool HasProfiles(ColorConvertedBitmapExtension ext) => ext?.SourceProfile != null && ext?.DestinationProfile != null;","tryCatchPattern":"try { var bmp = (BitmapSource)ext.ProvideValue(sp); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"profile\")) { /* supply profiles */ }","preventionTips":["Always supply both profiles: {ColorConvertedBitmap img, src.icm, dst.icm}","Ship .icm files with the app and reference them via pack URIs","Double-check after editing XAML that no argument was dropped"],"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"}