{"record":{"id":"e6f012add920fa93","repo":"dotnet/wpf","slug":"sr-collection-nonull-pathsegmentcollection","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/PathSegmentCollection.cs","lineNumber":128,"sourceCode":"\n        /// <summary>\n        ///     Returns the index of \"value\" in the list\n        /// </summary>\n        public int IndexOf(PathSegment 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, PathSegment 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(PathSegment value)","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathSegmentCollection.cs#L110-L146","documentation":"PathSegmentCollection.Insert throws ArgumentException with SR.Collection_NoNull when a null PathSegment is inserted. Null items are disallowed because segments participate in Freezable change notification and geometry rendering.","triggerScenarios":"Calling PathSegmentCollection.Insert(index, null) or IList.Insert with a null value; collection-initializer expressions that add a null segment.","commonSituations":"Building path geometry from optional segments where a line/arc variable is null; results of a factory method that returned null on failure being inserted directly.","solutions":["Guard with a null check before inserting and skip null segments.","Substitute a benign default segment (e.g. LineSegment) when the value would be null.","Fix the upstream factory/parsing code that produced a null segment."],"exampleFix":"// before\nsegments.Insert(0, maybeSegment);\n// after\nif (maybeSegment != null)\n{\n    segments.Insert(0, maybeSegment);\n}","handlingStrategy":"validation","validationCode":"if (segment == null) return; // or throw with context\nsegments.Insert(index, segment);","typeGuard":"bool IsValidSegment(PathSegment s) => s != null;","tryCatchPattern":null,"preventionTips":["Null-check segment factory results before insertion.","Use a default segment type (LineSegment) rather than null placeholders."],"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"}