PrismLibrary/Prism · error · ArgumentException
Resources.StringCannotBeNullOrEmpty (formatted with…
Error message
Resources.StringCannotBeNullOrEmpty (formatted with 'dependentModule')
What it means
This ArgumentException is thrown by ModuleDependencySolver.AddDependency when the 'dependentModule' argument is null or an empty string. Prism validates both module-name parameters before registering a dependency edge, because an empty edge would corrupt the dependency matrix used to compute the module load order.
Solutions
- Ensure the dependent module's ModuleName is set and non-empty before calling AddDependency
- Guard each dependency registration with String.IsNullOrWhiteSpace checks and skip or fix the bad entry
- If building from config, fix the module declaration so ModuleName is present
Example fix
// before
solver.AddDependency("ModuleA", moduleInfo.ModuleName); // ModuleName is ""
// after
if (!string.IsNullOrWhiteSpace(moduleInfo.ModuleName))
solver.AddDependency("ModuleA", moduleInfo.ModuleName); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(dependentModule))
throw new InvalidOperationException("dependentModule name must be non-empty before AddDependency"); Type guard
bool IsValidModuleName(string? name) => !string.IsNullOrWhiteSpace(name);
Try / catch
try
{
solver.AddDependency(depending, dependent);
}
catch (ArgumentException ex) when (ex.ParamName == "dependentModule")
{
logger.LogError(ex, "Empty dependent module name");
} Prevention
- Always set ModuleName on ModuleInfo before registering dependencies
- Validate names when building catalogs from config
- Prefer nameof or constants for module names
When it happens
Trigger: Calling AddDependency(dependingModule, dependentModule) with a null or "" dependentModule — e.g. reading ModuleInfo.ModuleName from a catalog entry whose Name was never set, or wiring dependencies programmatically before names are assigned.
Common situations: Module catalog entries declared in app.config/XAML with a missing ModuleName attribute; refactoring code that renamed a module constant to null; building catalogs dynamically from a data source that returns blank names.
Related errors
- Resources.DependencyForUnknownModule (formatted with…
- Value cannot be null. (Parameter 'name')
- Value cannot be null. (Parameter 'dependsOn')
- Value cannot be null. (Parameter 'type')
- Value cannot be null. (Parameter 'moduleInitializer')
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/153fdc293225db04.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Modularity/ModuleDependencySolver.cs:44
AddToDependencyMatrix(name);
AddToKnownModules(name);
}
/// <summary>
/// Adds a module dependency between the modules specified by dependingModule and
/// dependentModule.
/// </summary>
/// <param name="dependingModule">The name of the module with the dependency.</param>
/// <param name="dependentModule">The name of the module dependingModule
/// depends on.</param>
public void AddDependency(string dependingModule, string dependentModule)
{
if (String.IsNullOrEmpty(dependingModule))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, "dependingModule"));
if (String.IsNullOrEmpty(dependentModule))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, "dependentModule"));
if (!knownModules.Contains(dependingModule))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.DependencyForUnknownModule, dependingModule));
AddToDependencyMatrix(dependentModule);
dependencyMatrix.Add(dependentModule, dependingModule);
}
private void AddToDependencyMatrix(string module)
{
if (!dependencyMatrix.ContainsKey(module))
{
dependencyMatrix.Add(module);
}
}
private void AddToKnownModules(string module)
{View on GitHub (pinned to 358118cd64)