{"record":{"id":"d2ba15274b3fa4db","repo":"dotnet/wpf","slug":"sr-collection-nonull-pathfigurecollection","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/PathFigureCollection.cs","lineNumber":1022,"sourceCode":"                _collection = new FrugalStructList<PathFigure>(icollectionOfT);\n            }\n            else\n            {\n                ICollection icollection = collection as ICollection;\n\n                if (icollection != null) // an IC but not and IC<T>\n                {\n                    _collection = new FrugalStructList<PathFigure>(icollection);\n                }\n                else // not a IC or IC<T> so fall back to the slower Add\n                {\n                    _collection = new FrugalStructList<PathFigure>();\n\n                    foreach (PathFigure item in collection)\n                    {\n                        if (item == null)\n                        {\n                            throw new System.ArgumentException(SR.Collection_NoNull);\n                        }\n                        PathFigure newValue = item;\n                        OnFreezablePropertyChanged(/* oldValue = */ null, newValue);\n                        _collection.Add(newValue);\n\n                    }\n\n                    needsItemValidation = false;\n                }\n            }\n\n            if (needsItemValidation)\n            {\n                foreach (PathFigure item in collection)\n                {\n                    if (item == null)\n                    {\n                        throw new System.ArgumentException(SR.Collection_NoNull);","sourceCodeStart":1004,"sourceCodeEnd":1040,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollection.cs#L1004-L1040","documentation":"The PathFigureCollection(IEnumerable<PathFigure>) constructor throws ArgumentException with SR.Collection_NoNull when the source sequence contains a null PathFigure. Like other Freezable collections, null items are rejected during construction because each item is registered for change notification.","triggerScenarios":"Constructing a PathFigureCollection from an IEnumerable whose elements include null, e.g. new PathFigureCollection(list) where list contains null entries.","commonSituations":"Passing LINQ results built from nullable sources; collections populated from parsing where some figures failed to parse and were left null; combining arrays where a placeholder null was left in.","solutions":["Filter nulls before constructing: use collection.Where(f => f != null).","Fix the producer so it never yields null figures.","If nulls are meaningful, model them with an empty PathFigure or a nullable wrapper outside the collection."],"exampleFix":"// before\nvar figures = new PathFigureCollection(rawFigures);\n// after\nvar figures = new PathFigureCollection(rawFigures.Where(f => f != null));","handlingStrategy":"validation","validationCode":"if (collection == null || collection.Any(f => f == null))\n    throw new ArgumentException(\"Source sequence contains null PathFigures\");\nvar figures = new PathFigureCollection(collection);","typeGuard":"IEnumerable<PathFigure> NonNull(IEnumerable<PathFigure> src) => src?.Where(f => f != null) ?? Enumerable.Empty<PathFigure>();","tryCatchPattern":"try\n{\n    var figures = new PathFigureCollection(source);\n}\ncatch (ArgumentException)\n{\n    var figures = new PathFigureCollection(source.Where(f => f != null));\n}","preventionTips":["Filter source sequences with Where(f => f != null) before constructing.","Fix producers (parsers, factories) to skip instead of emit null figures."],"tags":["wpf","collection","null-check","constructor"],"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"}