{"record":{"id":"f51df5f86197df1f","repo":"dotnet/wpf","slug":"sr-image-noargument","errorCode":null,"errorMessage":"SR.Image_NoArgument","messagePattern":"SR\\.Image_NoArgument","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/ColorConvertedBitmap.cs","lineNumber":138,"sourceCode":"        /// </summary>\n        private void SourcePropertyChangedHook(DependencyPropertyChangedEventArgs e)\n        {\n            if (!e.IsASubPropertyChange)\n            {\n                BitmapSource newSource = e.NewValue as BitmapSource;\n                _source = newSource;\n                RegisterDownloadEventSource(_source);\n                _syncObject = (newSource != null) ? newSource.SyncObject : _bitmapInit;\n            }\n        }\n\n        internal override bool IsValidForFinalizeCreation(bool throwIfInvalid)\n        {\n            if (Source == null)\n            {\n                if (throwIfInvalid)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, \"Source\"));\n                }\n                return false;\n            }\n\n            if (SourceColorContext == null)\n            {\n                if (throwIfInvalid)\n                {\n                    throw new InvalidOperationException(SR.Color_NullColorContext);\n                }\n                return false;\n            }\n\n            if (DestinationColorContext == null)\n            {\n                if (throwIfInvalid)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, \"DestinationColorContext\"));","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/ColorConvertedBitmap.cs#L120-L156","documentation":"ColorConvertedBitmap requires a Source bitmap to convert. During EndInit, IsValidForFinalizeCreation detects Source == null and throws an InvalidOperationException (Image_NoArgument with parameter name \"Source\") because a color conversion cannot be finalized without an input image.","triggerScenarios":"new ColorConvertedBitmap { DestinationColorContext = ..., SourceColorContext = ... } inside a BeginInit/EndInit block without ever setting Source; setting only the color contexts in XAML.","commonSituations":"XAML data binding failing so the Source property is never set before EndInit; forgetting Source in code-built deferred initialization; a binding that resolves after EndInit runs.","solutions":["Set Source (a non-null BitmapSource) before calling EndInit","In XAML, set <ColorConvertedBitmap.Source> or the Source attribute explicitly","If using bindings, set Source synchronously or call BeginInit/EndInit only after the value is available"],"exampleFix":"// before\nvar ccb = new ColorConvertedBitmap();\nccb.BeginInit();\nccb.SourceColorContext = srcCtx;\nccb.DestinationColorContext = dstCtx;\nccb.EndInit(); // throws\n// after\nvar ccb = new ColorConvertedBitmap();\nccb.BeginInit();\nccb.Source = srcBitmap;\nccb.SourceColorContext = srcCtx;\nccb.DestinationColorContext = dstCtx;\nccb.EndInit();","handlingStrategy":"validation","validationCode":"if (ccb.Source == null) throw new ArgumentException(\"Set Source before EndInit\", nameof(source));","typeGuard":"static bool CanFinalize(ColorConvertedBitmap c) => c.Source != null && c.SourceColorContext != null && c.DestinationColorContext != null;","tryCatchPattern":"try { ccb.EndInit(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Source\")) { ccb.Source = fallbackBitmap; ccb.EndInit(); }","preventionTips":["Prefer the constructor overloads that take all arguments — they validate eagerly","Set every required property between BeginInit and EndInit in one place","In XAML, ensure Source is set via attribute or element, not a late-resolving binding"],"tags":["wpf","imaging","initialization"],"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-22T01:17:13.364Z"}