dotnet/wpf · error · ArgumentException
SR.Collection_NoNull
Error message
SR.Collection_NoNull
What it means
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.
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.
Example fix
// before
segments.Insert(0, maybeSegment);
// after
if (maybeSegment != null)
{
segments.Insert(0, maybeSegment);
} Defensive patterns
Strategy: validation
Validate before calling
if (segment == null) return; // or throw with context segments.Insert(index, segment);
Type guard
bool IsValidSegment(PathSegment s) => s != null;
Prevention
- Null-check segment factory results before insertion.
- Use a default segment type (LineSegment) rather than null placeholders.
When it happens
Trigger: Calling PathSegmentCollection.Insert(index, null) or IList.Insert with a null value; collection-initializer expressions that add a null segment.
Common situations: 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.
Related errors
- SR.Collection_NoNull
- SR.Collection_NoNull
- SR.Collection_NoNull
- SR.Collection_NoNull
- Cannot pass multidimensional array to the CopyTo method on…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e6f012add920fa93.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathSegmentCollection.cs:128
/// <summary>
/// Returns the index of "value" in the list
/// </summary>
public int IndexOf(PathSegment value)
{
ReadPreamble();
return _collection.IndexOf(value);
}
/// <summary>
/// Inserts "value" into the list at the specified position
/// </summary>
public void Insert(int index, PathSegment value)
{
if (value == null)
{
throw new System.ArgumentException(SR.Collection_NoNull);
}
WritePreamble();
OnFreezablePropertyChanged(/* oldValue = */ null, /* newValue = */ value);
_collection.Insert(index, value);
++_version;
WritePostscript();
}
/// <summary>
/// Removes "value" from the list
/// </summary>
public bool Remove(PathSegment value)View on GitHub (pinned to 81131a70a4)