{"record":{"id":"63c8c3fce21541c6","repo":"dotnet/wpf","slug":"sr-collection-nonull-transformcollection","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/Media/Generated/TransformCollection.cs","lineNumber":140,"sourceCode":"\n        /// <summary>\n        ///     Returns the index of \"value\" in the list\n        /// </summary>\n        public int IndexOf(Transform 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, Transform 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(Transform value)","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TransformCollection.cs#L122-L158","documentation":"TransformCollection.Insert throws ArgumentException(Collection_NoNull) when inserting a null Transform at a given index. Like TextEffectCollection, TransformCollection is a Freezable collection that forbids null items because each element participates in Freezable change tracking.","triggerScenarios":"Calling Insert(index, null) or inserting via a non-generic IList with a null boxed value.","commonSituations":"Binding or resource lookups that resolve to null then get inserted; generic collection-manipulation helpers that don't null-check; XAML data that failed to produce the transform.","solutions":["Null-check the value before calling Insert","If the null came from a FindResource call, use TryFindResource and skip missing values","Filter nulls from batch insert operations"],"exampleFix":"// before\ntransformCollection.Insert(0, FindResource(\"MyTransform\") as Transform); // may be null\n// after\nif (FindResource(\"MyTransform\") is Transform t)\n{\n    transformCollection.Insert(0, t);\n}","handlingStrategy":"validation","validationCode":"if (value == null) throw new ArgumentNullException(nameof(value));","typeGuard":"static bool CanInsert(Transform t) => t != null;","tryCatchPattern":"try { collection.Insert(index, value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"null\"))\n{ /* resolve or skip null transform */ }","preventionTips":["Use TryFindResource/`is Transform` pattern instead of `as` + unchecked insert","Null-check values coming from bindings, resources, or parsed XAML","In batch insert helpers, skip null entries explicitly"],"tags":["wpf","collections","null","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"}