{"record":{"id":"bd562c39f32d91bf","repo":"dotnet/wpf","slug":"sr-image-noargument-source","errorCode":null,"errorMessage":"SR.Image_NoArgument (Source)","messagePattern":"SR\\.Image_NoArgument \\(Source\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/TransformedBitmap.cs","lineNumber":277,"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            Transform transform = Transform;\n            if (transform == null)\n            {\n                if (throwIfInvalid)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, \"Transform\"));\n                }\n                return false;\n            }\n\n            if (!CheckTransform(transform))\n            {\n                if (throwIfInvalid)\n                {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/TransformedBitmap.cs#L259-L295","documentation":"TransformedBitmap.IsValidForFinalizeCreation runs during EndInit to verify the bitmap was fully initialized: Source must be non-null and the Transform must be set and orthogonal. If Source is null and throwIfInvalid is true (the normal EndInit path), it throws InvalidOperationException with SR.Image_NoArgument(\"Source\").","triggerScenarios":"Calling EndInit() on a TransformedBitmap after BeginInit() without assigning Source — e.g. the Source binding failed, assignment was skipped by an earlier exception, or EndInit was called out of order.","commonSituations":"Deferred/XAML-style initialization where the Source binding resolves after EndInit; manually constructed bitmaps where EndInit precedes property assignment; async decode pipelines that delay setting Source.","solutions":["Assign Source (and Transform) between BeginInit and EndInit before calling EndInit","Reorder initialization so EndInit is the last statement","Guard the call: if (bitmap.Source != null) bitmap.EndInit(); otherwise defer or supply a default source"],"exampleFix":"// before\nvar tb = new TransformedBitmap();\ntb.BeginInit();\ntb.Transform = new RotateTransform(90);\ntb.EndInit(); // throws: Source not set\n// after\nvar tb = new TransformedBitmap();\ntb.BeginInit();\ntb.Source = source;\ntb.Transform = new RotateTransform(90);\ntb.EndInit();","handlingStrategy":"validation","validationCode":"if (bitmap.Source == null)\n    throw new InvalidOperationException(\"Assign Source before calling EndInit\");","typeGuard":null,"tryCatchPattern":"try { bitmap.EndInit(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Source\"))\n{ /* assign Source (and Transform), then retry EndInit */ }","preventionTips":["Always set Source and Transform between BeginInit and EndInit","Make EndInit the final statement of the initialization block","When Source comes from a binding, confirm the binding resolved before EndInit runs"],"tags":["wpf","bitmapsource","initialization","missing-source"],"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"}