PrismLibrary/Prism · error · ArgumentException
Resources.StringCannotBeNullOrEmpty (formatted with 'name')
Error message
Resources.StringCannotBeNullOrEmpty (formatted with 'name')
What it means
ModuleDependencySolver.AddModule throws ArgumentException with Resources.StringCannotBeNullOrEmpty when the module name is null or empty. Module names are the solver's identity keys for ordering and cycle detection, so a null/empty name is rejected immediately.
Solutions
- Set a non-empty ModuleName on every IModuleInfo added to the catalog.
- Check the module definition source (code, XAML, app.config) for a missing name attribute.
- Add a pre-validation pass that rejects modules with string.IsNullOrWhiteSpace(ModuleName).
Example fix
// before
var module = new ModuleInfo { ModuleType = typeof(MyModule).AssemblyQualifiedName }; // ModuleName empty
// after
var module = new ModuleInfo { ModuleName = "MyModule", ModuleType = typeof(MyModule).AssemblyQualifiedName }; Defensive patterns
Strategy: validation
Validate before calling
if (modules.Any(m => string.IsNullOrWhiteSpace(m.ModuleName)))
throw new InvalidOperationException("All modules must have a non-empty ModuleName before catalog validation"); Type guard
bool HasName(IModuleInfo m) => !string.IsNullOrWhiteSpace(m?.ModuleName);
Try / catch
try
{
catalog.Validate();
}
catch (ArgumentException ex) when (ex.Message.Contains("name"))
{
logger.LogError(ex, "A module with an empty ModuleName reached the dependency solver");
} Prevention
- Always set ModuleName when constructing ModuleInfo
- Validate module definitions parsed from config/XAML for a name attribute
- Filter or reject modules with whitespace-only names early
When it happens
Trigger: Calling solver.AddModule(null) or AddModule("") directly, or indirectly when SolveDependencies iterates a catalog containing an IModuleInfo whose ModuleName is null or empty.
Common situations: Programmatically created ModuleInfo objects with the name forgotten; config/XAML entries missing the module name attribute; data binding that produced an empty name.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Resources.StringCannotBeNullOrEmpty (formatted with…
- Resources.RegionNameCannotBeEmptyException
- The region name cannot be null or empty.
- The provided String argument
- Resources.StringCannotBeNullOrEmpty
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/a4ed00110fd9d4d2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Modularity/ModuleDependencySolver.cs:25
namespace Prism.Modularity
{
/// <summary>
/// Used by <see cref="IModuleInitializer"/> to get the load sequence
/// for the modules to load according to their dependencies.
/// </summary>
public class ModuleDependencySolver
{
private readonly ListDictionary<string, string> dependencyMatrix = new ListDictionary<string, string>();
private readonly List<string> knownModules = new List<string>();
/// <summary>
/// Adds a module to the solver.
/// </summary>
/// <param name="name">The name that uniquely identifies the module.</param>
public void AddModule(string name)
{
if (String.IsNullOrEmpty(name))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, "name"));
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))View on GitHub (pinned to 358118cd64)