PrismLibrary/Prism · error · ArgumentNullException
ArgumentNullException(nameof(behaviorType))
Error message
ArgumentNullException(nameof(behaviorType))
What it means
Validation guard in RegionBehaviorFactory.AddIfMissing: the factory resolves the behavior instance from behaviorType via the container; a null Type cannot be instantiated or registered, so ArgumentNullException naming 'behaviorType' is thrown after the null-key check.
Solutions
- Pass typeof(MyBehavior) directly instead of Type.GetType on a string
- If using Type.GetType, check for null and include the assembly-qualified name
- Ensure the assembly containing the behavior is referenced and loaded
Example fix
// before
var t = Type.GetType("MyBehavior"); // null
factory.AddIfMissing(key, t);
// after
factory.AddIfMissing(key, typeof(MyBehavior)); Defensive patterns
Strategy: validation
Validate before calling
var t = Type.GetType(name);
if (t == null) throw new InvalidOperationException($"Type {name} not found");
factory.AddIfMissing(key, t); Type guard
bool ResolvableType(string n) => Type.GetType(n, throwOnError: false) != null;
Try / catch
try { factory.AddIfMissing(key, t); } catch (ArgumentNullException ex) when (ex.ParamName == "behaviorType") { /* resolve type */ } Prevention
- Prefer typeof(T) over Type.GetType strings
- Use assembly-qualified names when reflecting
- Fail fast on null Type resolution
When it happens
Trigger: Calling AddIfMissing(key, null) — e.g. typeof resolution from a string via Type.GetType that returned null because the assembly-qualified name was wrong.
Common situations: Type.GetType with a wrong or incomplete assembly-qualified name (returns null silently); loading behavior types from config; assembly not referenced/loaded in a plugin scenario.
Related errors
- ArgumentNullException(nameof(key))
- ArgumentNullException(nameof(regionBehavior))
- ArgumentNullException(nameof(behaviorKey))
- Layout 's Children property is not empty. This control is…
- regionName
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/03f16bd334525b96.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Navigation/Regions/RegionBehaviorFactory.cs:42
{
_container = container;
}
/// <summary>
/// Adds a particular type of RegionBehavior if it was not already registered. The <paramref name="behaviorKey"/> string is used to check if the behavior is already present
/// </summary>
/// <param name="behaviorKey">The behavior key that's used to find if a certain behavior is already added.</param>
/// <param name="behaviorType">Type of the behavior to add.</param>
public void AddIfMissing(string behaviorKey, Type behaviorType)
{
if (behaviorKey == null)
{
throw new ArgumentNullException(nameof(behaviorKey));
}
if (behaviorType == null)
{
throw new ArgumentNullException(nameof(behaviorType));
}
// Check if the type is a IRegionBehavior
if (!typeof(IRegionBehavior).IsAssignableFrom(behaviorType))
{
throw new ArgumentException(
string.Format(Thread.CurrentThread.CurrentCulture, Resources.CanOnlyAddTypesThatInheritIFromRegionBehavior, behaviorType.Name), nameof(behaviorType));
}
// Only add the behaviorKey if it doesn't already exists.
if (_registeredBehaviors.ContainsKey(behaviorKey))
{
return;
}
_registeredBehaviors.Add(behaviorKey, behaviorType);
}
View on GitHub (pinned to 358118cd64)