PrismLibrary/Prism · error · ArgumentException

Resources.StringCannotBeNullOrEmpty (formatted with…

Error message

Resources.StringCannotBeNullOrEmpty (formatted with 'dependingModule')

What it means

ModuleDependencySolver.AddDependency throws ArgumentException with Resources.StringCannotBeNullOrEmpty when dependingModule or dependentModule is null/empty, and DependencyForUnknownModule when dependingModule was never added via AddModule. The solver can only record edges between known module names.

Solutions

  1. Ensure both module names are non-empty and that AddModule was called for the depending module before AddDependency.
  2. Fix DependsOn entries in the module definitions to match exactly the registered ModuleName values.
  3. Use SolveDependencies/ValidateDependencyGraph on the full catalog so all modules are added before dependency edges are resolved.

Example fix

// before
solver.AddDependency("", "Core");
// after
if (!string.IsNullOrEmpty(dependingModule) && !string.IsNullOrEmpty(dependentModule))
{
    solver.AddModule(dependingModule);
    solver.AddDependency(dependingModule, dependentModule);
}
Defensive patterns

Strategy: validation

Validate before calling

var known = modules.Select(m => m.ModuleName).ToHashSet();
foreach (var m in modules)
{
    foreach (var d in m.DependsOn ?? Enumerable.Empty<string>())
    {
        if (string.IsNullOrWhiteSpace(d) || !known.Contains(d))
            throw new InvalidOperationException($"Module '{m.ModuleName}' has invalid dependency '{d}'");
    }
}

Type guard

bool IsKnownDependency(string d, ISet<string> known) => !string.IsNullOrWhiteSpace(d) && known.Contains(d);

Try / catch

try
{
    catalog.Validate();
}
catch (ArgumentException ex)
{
    logger.LogError(ex, "Dependency solver rejected a module/dependency name: {0}", ex.Message);
}

Prevention

When it happens

Trigger: Calling AddDependency(null, x), AddDependency("", x), AddDependency(x, null), or AddDependency("Unknown", x) where "Unknown" was not previously registered with AddModule; reached indirectly from SolveDependencies when a catalog's DependsOn contains empty strings or references modules added after the dependency pass.

Common situations: DependsOn arrays containing empty entries from config parsing; a typo'd dependency name that matches no registered module; a custom catalog that adds dependencies before adding all modules.

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


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/6f12ca5c9efa0302. Report an issue: GitHub.

Appendix: source

Thrown at src/Prism.Core/Modularity/ModuleDependencySolver.cs:41

        {
            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))
                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);
            }
        }

View on GitHub (pinned to 358118cd64)