{"record":{"id":"c830a6faacde9f76","repo":"dotnet/wpf","slug":"sr-collection-nonull-transform3dcollection","errorCode":null,"errorMessage":"SR.Collection_NoNull","messagePattern":"SR\\.Collection_NoNull","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DCollection.cs","lineNumber":138,"sourceCode":"\n        /// <summary>\n        ///     Returns the index of \"value\" in the list\n        /// </summary>\n        public int IndexOf(Transform3D value)\n        {\n            ReadPreamble();\n\n            return _collection.IndexOf(value);\n        }\n\n        /// <summary>\n        ///     Inserts \"value\" into the list at the specified position\n        /// </summary>\n        public void Insert(int index, Transform3D value)\n        {\n            if (value == null)\n            {\n                throw new System.ArgumentException(SR.Collection_NoNull);\n            }\n\n            WritePreamble();\n\n            OnFreezablePropertyChanged(/* oldValue = */ null, /* newValue = */ value);\n\n            _collection.Insert(index, value);\n            OnInsert(value);\n\n\n            ++_version;\n            WritePostscript();\n        }\n\n        /// <summary>\n        ///     Removes \"value\" from the list\n        /// </summary>\n        public bool Remove(Transform3D value)","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DCollection.cs#L120-L156","documentation":"Transform3DCollection.Insert rejects a null Transform3D value and throws ArgumentException with SR.Collection_NoNull. WPF's Freezable-based typed collections disallow null elements because entries feed the render pipeline, which requires a valid transform instance. This mirrors the standard behavior of WPF generated collection types.","triggerScenarios":"Calling Insert(int index, Transform3D value) with a null value, e.g. collection.Insert(0, null) or inserting the result of a lookup that returned null.","commonSituations":"Binding a Transform3D from XAML or data where the value failed to resolve; a factory method returning null; refactoring code where a Transform3D field was never initialized.","solutions":["Check the value for null before calling Insert and skip or substitute a default (e.g. TransformGroup or MatrixTransform.Identity).","Use RemoveAt/Remove instead of inserting null to delete an element.","Fix the upstream source so it produces a real Transform3D instead of null."],"exampleFix":"// before\ncollection.Insert(0, GetTransform());\n// after\nvar t = GetTransform();\nif (t != null) collection.Insert(0, t);","handlingStrategy":"validation","validationCode":"if (value == null) throw new ArgumentException(nameof(value));\ncollection.Insert(index, value);","typeGuard":"bool IsValid(Transform3D t) => t != null;","tryCatchPattern":"try { collection.Insert(i, value); } catch (ArgumentException) { /* substitute default or log */ }","preventionTips":["Null-check transforms from data binding or factories before inserting","Use RemoveAt to delete elements rather than assigning/inserting null","Prefer identity transforms as neutral values"],"tags":["wpf","collection","null-check","argumentexception"],"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"}