{"record":{"id":"f92f47d77da2d461","repo":"dotnet/wpf","slug":"sr-collection-nonull-texteffectcollection","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/TextEffectCollection.cs","lineNumber":128,"sourceCode":"\n        /// <summary>\n        ///     Returns the index of \"value\" in the list\n        /// </summary>\n        public int IndexOf(TextEffect 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, TextEffect 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\n\n\n            ++_version;\n            WritePostscript();\n        }\n\n        /// <summary>\n        ///     Removes \"value\" from the list\n        /// </summary>\n        public bool Remove(TextEffect value)","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/TextEffectCollection.cs#L110-L146","documentation":"TextEffectCollection.Insert(int index, TextEffect value) throws ArgumentException(Collection_NoNull) when the value being inserted is null. Unlike some BCL collections that tolerate null reference-type elements, Freezable-derived WPF collections disallow null items because each element participates in the Freezable change/inheritance machinery (OnFreezablePropertyChanged).","triggerScenarios":"Calling ((IList)textEffectCollection).Insert(i, null) or the typed Insert(i, (TextEffect)null) — commonly when the item came from an uninitialized variable or a failed lookup that returned null.","commonSituations":"Data pipelines that pass null placeholders for 'no effect'; LINQ queries that produce null entries; late-bound/reflection code inserting items into the non-generic IList.","solutions":["Filter nulls before inserting: if (value != null) collection.Insert(i, value);","Throw or log upstream so nulls never reach the collection call.","Use OfType<TextEffect>() or Where(e => e != null) when bulk-inserting from a query."],"exampleFix":"// before\nTextEffect effect = FindEffect(name); // may be null\ncollection.Insert(0, effect); // ArgumentException Collection_NoNull\n// after\nTextEffect effect = FindEffect(name);\nif (effect != null) collection.Insert(0, effect);","handlingStrategy":"type-guard","validationCode":"if (value == null) throw new ArgumentNullException(nameof(value)); // before calling Insert","typeGuard":"static bool IsValidItem(object v) => v is TextEffect;","tryCatchPattern":"try { collection.Insert(i, effect); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Collection_NoNull\")) { /* skip or substitute a default TextEffect */ }","preventionTips":["Null-check items from lookups/queries before inserting.","Filter with Where(e => e != null) when bulk-inserting.","Remember WPF Freezable collections reject null elements — use RemoveAt to remove."],"tags":["wpf","collection","argumentexception","null"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}