PrismLibrary/Prism · error · ArgumentException

Resources.DependencyForUnknownModule (formatted with…

Error message

Resources.DependencyForUnknownModule (formatted with dependingModule)

What it means

This ArgumentException is thrown when AddDependency is called with a 'dependingModule' that has never been added to the solver via AddModule. The solver only allows declaring dependencies between modules it already knows about, preventing edges pointing at unknown nodes.

Solutions

  1. Call AddModule(dependingModule) for every module before calling AddDependency
  2. Verify the depending module name matches exactly the name passed to AddModule (case-sensitive)
  3. Reorder initialization: populate all known modules first, then add dependency edges

Example fix

// before
solver.AddDependency("ModuleA", "ModuleB"); // ModuleA never added
// after
solver.AddModule("ModuleA");
solver.AddModule("ModuleB");
solver.AddDependency("ModuleA", "ModuleB");
Defensive patterns

Strategy: validation

Validate before calling

foreach (var dep in dependencies)
    if (!knownModules.Contains(dep.Dependant))
        throw new InvalidOperationException($"{dep.Dependant} must be added via AddModule first");

Type guard

bool IsKnownModule(ModuleDependencySolver s, string name) => s.KnownModules.Contains(name);

Try / catch

try
{
    solver.AddDependency(depending, dependent);
}
catch (ArgumentException ex) when (ex.ParamName == null)
{
    // DependencyForUnknownModule path
    logger.LogError(ex, "Unknown module {0}", depending);
}

Prevention

When it happens

Trigger: Calling AddDependency("ModuleA", "ModuleB") where "ModuleA" was never registered with AddModule("ModuleA") first; a typo in the module name; adding dependencies before populating the known module list.

Common situations: Registering modules in a loop but wiring dependencies in a separate pass where a name was mistyped; a module removed from the catalog while its consumers still reference it; ordering bugs where dependencies are added before modules.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

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

        }

        /// <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)
        {
            if (!knownModules.Contains(module))
            {
                knownModules.Add(module);

View on GitHub (pinned to 358118cd64)