{"record":{"id":"80b855ef28a6b79b","repo":"dotnet/wpf","slug":"sr-collection-nonull-geometrycollection","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/GeometryCollection.cs","lineNumber":140,"sourceCode":"\n        /// <summary>\n        ///     Returns the index of \"value\" in the list\n        /// </summary>\n        public int IndexOf(Geometry 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, Geometry 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(Geometry value)","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/GeometryCollection.cs#L122-L158","documentation":"GeometryCollection.Insert throws ArgumentException with SR.Collection_NoNull when the caller attempts to insert a null Geometry into the collection. WPF Freezable collections disallow null items because items participate in inheritance context, change notification, and rendering, all of which require a valid instance.","triggerScenarios":"Calling GeometryCollection.Insert(index, null) or any API that routes into Insert (e.g. IList.Insert) with a null value.","commonSituations":"Building geometry groups from optional data where a geometry variable is null because parsing or a lookup failed; passing results of a method that returns Geometry? straight into the collection.","solutions":["Check for null before inserting and skip or substitute a default Geometry (e.g. Geometry.Empty).","Initialize the null source variable or fix the upstream code that produced a null Geometry.","Use Add with a guard clause so the failure point is clearer if you need to debug where nulls originate."],"exampleFix":"// before\ngeometryCollection.Insert(0, maybeGeometry);\n// after\nif (maybeGeometry != null)\n{\n    geometryCollection.Insert(0, maybeGeometry);\n}","handlingStrategy":"validation","validationCode":"if (geometry == null) throw new ArgumentException(\"Cannot insert a null Geometry\", nameof(geometry));\ngeometryCollection.Insert(index, geometry);","typeGuard":"bool IsValidGeometry(Geometry g) => g != null;","tryCatchPattern":null,"preventionTips":["Never insert values straight from nullable-returning APIs without a null check.","Default to Geometry.Empty instead of null for placeholder geometries."],"tags":["wpf","collection","null-check"],"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"}