dotnet/wpf · error · ArgumentException
SR.Collection_NoNull
Error message
SR.Collection_NoNull
What it means
The FreezableCollection(T) constructor accepting an IEnumerable(T) throws ArgumentException (SR.Collection_NoNull) if any element of the source collection is null. Freezable collections never permit null items because null cannot be frozen/validated as a Freezable element.
Solutions
- Filter nulls before constructing: collection.Where(x => x != null).
- Fix the upstream producer so it never emits null elements.
- If nulls are meaningful, wrap items in a nullable-holder type instead.
Example fix
// before var col = new FreezableCollection<Geometry>(rawList); // after var col = new FreezableCollection<Geometry>(rawList.Where(g => g != null));
Defensive patterns
Strategy: validation
Validate before calling
if (source.Any(item => item == null)) throw new InvalidOperationException("Source contains null items"); Try / catch
try { col = new FreezableCollection<T>(source); } catch (ArgumentException) { col = new FreezableCollection<T>(source.Where(x => x != null)); } Prevention
- Filter nulls from enumerable sources before constructing.
- Ensure upstream producers never emit null items.
- Model 'missing' values with a default instance rather than null.
When it happens
Trigger: new FreezableCollection<T>(someEnumerable) where someEnumerable contains one or more null references.
Common situations: Initializing a collection from LINQ results, deserialized data, or an array built incrementally where nulls slipped in; e.g. new FreezableCollection<Geometry>(geometries) with geometries containing nulls.
Related errors
- DoubleKeyFrameCollection
- Int16KeyFrameCollection
- MatrixKeyFrameCollection
- ObjectKeyFrameCollection
- Point3DKeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c9a8f79dc0d260b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FreezableCollection.cs:81
ArgumentNullException.ThrowIfNull(collection);
int count = GetCount(collection);
if (count > 0)
{
_collection = new List<T>(count);
}
else
{
_collection = new List<T>();
}
foreach (T item in collection)
{
if (item == null)
{
throw new System.ArgumentException(SR.Collection_NoNull);
}
OnFreezablePropertyChanged(oldValue: null, item);
_collection.Add(item);
}
WritePostscript();
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
View on GitHub (pinned to 81131a70a4)