{"record":{"id":"cf956d4a98d016f1","repo":"dotnet/wpf","slug":"sr-image-noargument-transform","errorCode":null,"errorMessage":"SR.Image_NoArgument (Transform)","messagePattern":"SR\\.Image_NoArgument \\(Transform\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/TransformedBitmap.cs","lineNumber":36,"sourceCode":"        /// </summary>\n        public TransformedBitmap()\n            : base(true) // Use base class virtuals\n        {\n        }\n\n        /// <summary>\n        /// Construct a TransformedBitmap with the given newTransform\n        /// </summary>\n        /// <param name=\"source\">BitmapSource to apply to the newTransform to</param>\n        /// <param name=\"newTransform\">Transform to apply to the bitmap</param>\n        public TransformedBitmap(BitmapSource source, Transform newTransform)\n            : base(true) // Use base class virtuals\n        {\n            ArgumentNullException.ThrowIfNull(source);\n\n            if (newTransform == null)\n            {\n                throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, \"Transform\"));\n            }\n\n            if (!CheckTransform(newTransform))\n            {\n                throw new InvalidOperationException(SR.Image_OnlyOrthogonal);\n            }\n\n            _bitmapInit.BeginInit();\n\n            Source = source;\n            Transform = newTransform;\n\n            _bitmapInit.EndInit();\n            FinalizeCreation();\n        }\n\n        // ISupportInitialize\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/TransformedBitmap.cs#L18-L54","documentation":"The TransformedBitmap(source, transform) constructor requires both a non-null source and a non-null transform; a null transform yields no valid bitmap definition, so it throws InvalidOperationException with SR.Image_NoArgument(\"Transform\"). The source null case is already handled by ArgumentNullException.ThrowIfNull.","triggerScenarios":"new TransformedBitmap(source, transform) where a nullable Transform variable is null — e.g. an optional transform resolved to null, or a transform factory returned null before the constructor call.","commonSituations":"Optional rotation logic that skips assignment when no rotation is needed; transform created from deserialized/config data that failed to resolve; BeginInit-style code refactored into direct construction with an unset Transform property.","solutions":["Pass Transform.Identity instead of null when no transform is needed","Use the source bitmap directly rather than wrapping in TransformedBitmap when no transform applies","Coalesce the nullable transform: new TransformedBitmap(source, transform ?? Transform.Identity)"],"exampleFix":"// before\nTransform transform = GetOptionalTransform(); // may be null\nvar tb = new TransformedBitmap(source, transform);\n// after\nTransform transform = GetOptionalTransform() ?? Transform.Identity;\nvar tb = new TransformedBitmap(source, transform);","handlingStrategy":"validation","validationCode":"if (transform == null)\n    throw new ArgumentException(\"Transform must not be null\", nameof(transform));","typeGuard":"static bool HasTransform(Transform t) => t != null;","tryCatchPattern":"try { var tb = new TransformedBitmap(source, transform); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Transform\"))\n{ /* supply Transform.Identity fallback */ }","preventionTips":["Coalesce optional transforms with ?? Transform.Identity","Never pass raw nullable transform fields into bitmap constructors","Prefer BeginInit/EndInit with explicit property assignment so missing parts fail clearly"],"tags":["wpf","transform","null-argument","invalidoperationexception"],"backgroundTag":"null-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"}