PrismLibrary/Prism · error · ArgumentNullException
value
Error message
value
What it means
A validation guard in ListDictionary<TKey,TValue>.Add(TKey,TValue): a null value argument is rejected with ArgumentNullException naming 'value', because storing null values under a key would corrupt the list-of-values semantics the dictionary guarantees. The input at fault is the null value passed to Add.
Solutions
- Ensure the value (e.g. handler delegate) is created before Add
- Skip the Add call when the value is null
Example fix
// before listDictionary.Add(key, handler); // after if (handler != null) listDictionary.Add(key, handler);
Defensive patterns
Strategy: validation
Validate before calling
if (value == null) throw new InvalidOperationException("value must be non-null before ListDictionary.Add"); Type guard
static bool ValidValue<TValue>(TValue v) => v != null;
Try / catch
try { dict.Add(key, handler); }
catch (ArgumentNullException) when (handler == null) { /* handler never initialized */ } Prevention
- Create the delegate/handler before registration
- Skip or log when a handler is null instead of adding
- Initialize handler fields at construction time
When it happens
Trigger: Calling Add(validKey, null), often when a delegate/handler variable is null because subscription failed or the target was collected.
Common situations: Event aggregator style code registering a null handler reference, or lambdas assigned conditionally that ended up null.
Related errors
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/ec216d06ec8586d4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Common/ListDictionary.cs:38
if (key == null)
throw new ArgumentNullException(nameof(key));
CreateNewList(key);
}
/// <summary>
/// Adds a value to a list with the given key. If a list does not already exist,
/// it will be created automatically.
/// </summary>
/// <param name="key">The key of the list that will hold the value.</param>
/// <param name="value">The value to add to the list under the given key.</param>
public void Add(TKey key, TValue value)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
if (value == null)
throw new ArgumentNullException(nameof(value));
if (innerValues.ContainsKey(key))
{
innerValues[key].Add(value);
}
else
{
List<TValue> values = CreateNewList(key);
values.Add(value);
}
}
private List<TValue> CreateNewList(TKey key)
{
List<TValue> values = new List<TValue>();
innerValues.Add(key, values);
return values;View on GitHub (pinned to 358118cd64)