PrismLibrary/Prism · error · ArgumentNullException
Value cannot be null. (Parameter 'dependsOn')
Error message
Value cannot be null. (Parameter 'dependsOn')
What it means
ModuleInfo's main constructor throws ArgumentNullException when the dependsOn array is null. Explicitly passing null as the params argument triggers this, while omitting the argument yields an empty array which is fine. The catalog needs a (possibly empty) dependency list.
Solutions
- Omit the argument for no dependencies: new ModuleInfo("Foo", type)
- Pass an empty array: Array.Empty<string>() or new string[0]
- Coalesce null dependency collections: dependsOn ?? Array.Empty<string>()
Example fix
// before
var info = new ModuleInfo("FooModule", typeof(FooModule).AssemblyQualifiedName, dependencies); // dependencies is null
// after
var info = new ModuleInfo("FooModule", typeof(FooModule).AssemblyQualifiedName, dependencies ?? Array.Empty<string>()); Defensive patterns
Strategy: validation
Validate before calling
var deps = configuredDependencies ?? Array.Empty<string>();
var info = new ModuleInfo("FooModule", typeof(FooModule).AssemblyQualifiedName, deps); Try / catch
try
{
var info = new ModuleInfo(name, type, dependencies);
}
catch (ArgumentNullException ex) when (ex.ParamName == "dependsOn")
{
logger.LogWarning("Null dependency list for {Module}; treating as none", name);
var info = new ModuleInfo(name, type);
} Prevention
- Omit the params argument instead of passing null when a module has no dependencies
- Coalesce nullable dependency collections with ?? Array.Empty<string>()
- Remember params parameters accept omission but throw on explicit null here
When it happens
Trigger: new ModuleInfo("Foo", type, null) — explicitly passing null as the params argument instead of omitting it; forwarding a nullable dependency collection that is null.
Common situations: Programmatic module catalog construction where a dependencies list from config was null and passed straight through; overload confusion where callers assume params can be null.
Related errors
- Value cannot be null. (Parameter 'name')
- Value cannot be null. (Parameter 'type')
- Value cannot be null. (Parameter 'moduleInitializer')
- IModuleCatalog was null
- Value cannot be null. (Parameter 'moduleCatalog')
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/0c61dad72c09250d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Modularity/ModuleInfo.cs:36
/// Initializes a new empty instance of <see cref="ModuleInfo"/>.
/// </summary>
public ModuleInfo()
{
}
/// <summary>
/// Initializes a new instance of <see cref="ModuleInfo"/>.
/// </summary>
/// <param name="name">The module's name.</param>
/// <param name="type">The module <see cref="Type"/>'s AssemblyQualifiedName.</param>
/// <param name="dependsOn">The modules this instance depends on.</param>
/// <exception cref="ArgumentNullException">An <see cref="ArgumentNullException"/> is thrown if <paramref name="dependsOn"/> is <see langword="null"/>.</exception>
public ModuleInfo(string name, string type, params string[] dependsOn)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
if (dependsOn == null)
throw new ArgumentNullException(nameof(dependsOn));
ModuleType = Type.GetType(type) ?? throw new ArgumentNullException(nameof(type));
ModuleName = name;
foreach (string dependency in dependsOn)
{
if (!DependsOn.Contains(dependency))
{
DependsOn.Add(dependency);
}
}
}
/// <summary>
/// Initializes a new instance of <see cref="ModuleInfo"/>.
/// </summary>
/// <param name="name">The module's name.</param>
/// <param name="type">The module's type.</param>
public ModuleInfo(string name, string type)View on GitHub (pinned to 358118cd64)