dotnet/wpf · error · ArgumentException
SR.Collection_NoNull
Error message
SR.Collection_NoNull
What it means
Transform3DCollection.Insert rejects a null Transform3D value and throws ArgumentException with SR.Collection_NoNull. WPF's Freezable-based typed collections disallow null elements because entries feed the render pipeline, which requires a valid transform instance. This mirrors the standard behavior of WPF generated collection types.
Solutions
- Check the value for null before calling Insert and skip or substitute a default (e.g. TransformGroup or MatrixTransform.Identity).
- Use RemoveAt/Remove instead of inserting null to delete an element.
- Fix the upstream source so it produces a real Transform3D instead of null.
Example fix
// before collection.Insert(0, GetTransform()); // after var t = GetTransform(); if (t != null) collection.Insert(0, t);
Defensive patterns
Strategy: validation
Validate before calling
if (value == null) throw new ArgumentException(nameof(value)); collection.Insert(index, value);
Type guard
bool IsValid(Transform3D t) => t != null;
Try / catch
try { collection.Insert(i, value); } catch (ArgumentException) { /* substitute default or log */ } Prevention
- Null-check transforms from data binding or factories before inserting
- Use RemoveAt to delete elements rather than assigning/inserting null
- Prefer identity transforms as neutral values
When it happens
Trigger: Calling Insert(int index, Transform3D value) with a null value, e.g. collection.Insert(0, null) or inserting the result of a lookup that returned null.
Common situations: Binding a Transform3D from XAML or data where the value failed to resolve; a factory method returning null; refactoring code where a Transform3D field was never initialized.
Related errors
- SR.Collection_NoNull
- SR.Collection_BadDestArray
- SR.Collection_BadDestArray
- SR.Collection_BadRank
- SR.Collection_BadRank
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c830a6faacde9f76.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DCollection.cs:138
/// <summary>
/// Returns the index of "value" in the list
/// </summary>
public int IndexOf(Transform3D value)
{
ReadPreamble();
return _collection.IndexOf(value);
}
/// <summary>
/// Inserts "value" into the list at the specified position
/// </summary>
public void Insert(int index, Transform3D value)
{
if (value == null)
{
throw new System.ArgumentException(SR.Collection_NoNull);
}
WritePreamble();
OnFreezablePropertyChanged(/* oldValue = */ null, /* newValue = */ value);
_collection.Insert(index, value);
OnInsert(value);
++_version;
WritePostscript();
}
/// <summary>
/// Removes "value" from the list
/// </summary>
public bool Remove(Transform3D value)View on GitHub (pinned to 81131a70a4)