dotnet/wpf · error · ArgumentException
SR.Collection_NoNull
Error message
SR.Collection_NoNull
What it means
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.
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.
Example fix
// before var figures = new PathFigureCollection(rawFigures); // after var figures = new PathFigureCollection(rawFigures.Where(f => f != null));
Defensive patterns
Strategy: validation
Validate before calling
if (collection == null || collection.Any(f => f == null))
throw new ArgumentException("Source sequence contains null PathFigures");
var figures = new PathFigureCollection(collection); Type guard
IEnumerable<PathFigure> NonNull(IEnumerable<PathFigure> src) => src?.Where(f => f != null) ?? Enumerable.Empty<PathFigure>();
Try / catch
try
{
var figures = new PathFigureCollection(source);
}
catch (ArgumentException)
{
var figures = new PathFigureCollection(source.Where(f => f != null));
} Prevention
- Filter source sequences with Where(f => f != null) before constructing.
- Fix producers (parsers, factories) to skip instead of emit null figures.
When it happens
Trigger: Constructing a PathFigureCollection from an IEnumerable whose elements include null, e.g. new PathFigureCollection(list) where list contains null entries.
Common situations: 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.
Related errors
- SR.Collection_NoNull
- SR.Collection_NoNull
- SR.Collection_NoNull
- SR.Collection_NoNull
- ArgumentNullException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d2ba15274b3fa4db.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollection.cs:1022
_collection = new FrugalStructList<PathFigure>(icollectionOfT);
}
else
{
ICollection icollection = collection as ICollection;
if (icollection != null) // an IC but not and IC<T>
{
_collection = new FrugalStructList<PathFigure>(icollection);
}
else // not a IC or IC<T> so fall back to the slower Add
{
_collection = new FrugalStructList<PathFigure>();
foreach (PathFigure item in collection)
{
if (item == null)
{
throw new System.ArgumentException(SR.Collection_NoNull);
}
PathFigure newValue = item;
OnFreezablePropertyChanged(/* oldValue = */ null, newValue);
_collection.Add(newValue);
}
needsItemValidation = false;
}
}
if (needsItemValidation)
{
foreach (PathFigure item in collection)
{
if (item == null)
{
throw new System.ArgumentException(SR.Collection_NoNull);View on GitHub (pinned to 81131a70a4)