{"record":{"id":"6f12ca5c9efa0302","repo":"PrismLibrary/Prism","slug":"resources-stringcannotbenullorempty-formatted-with","errorCode":null,"errorMessage":"Resources.StringCannotBeNullOrEmpty (formatted with 'dependingModule')","messagePattern":"Resources\\.StringCannotBeNullOrEmpty \\(formatted with 'dependingModule'\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Modularity/ModuleDependencySolver.cs","lineNumber":41,"sourceCode":"        {\n            if (String.IsNullOrEmpty(name))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, \"name\"));\n\n            AddToDependencyMatrix(name);\n            AddToKnownModules(name);\n        }\n\n        /// <summary>\n        /// Adds a module dependency between the modules specified by dependingModule and\n        /// dependentModule.\n        /// </summary>\n        /// <param name=\"dependingModule\">The name of the module with the dependency.</param>\n        /// <param name=\"dependentModule\">The name of the module dependingModule\n        /// depends on.</param>\n        public void AddDependency(string dependingModule, string dependentModule)\n        {\n            if (String.IsNullOrEmpty(dependingModule))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, \"dependingModule\"));\n\n            if (String.IsNullOrEmpty(dependentModule))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, \"dependentModule\"));\n\n            if (!knownModules.Contains(dependingModule))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.DependencyForUnknownModule, dependingModule));\n\n            AddToDependencyMatrix(dependentModule);\n            dependencyMatrix.Add(dependentModule, dependingModule);\n        }\n\n        private void AddToDependencyMatrix(string module)\n        {\n            if (!dependencyMatrix.ContainsKey(module))\n            {\n                dependencyMatrix.Add(module);\n            }\n        }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Modularity/ModuleDependencySolver.cs#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure both module names are non-empty and that AddModule was called for the depending module before AddDependency.","Fix DependsOn entries in the module definitions to match exactly the registered ModuleName values.","Use SolveDependencies/ValidateDependencyGraph on the full catalog so all modules are added before dependency edges are resolved."],"exampleFix":"// before\nsolver.AddDependency(\"\", \"Core\");\n// after\nif (!string.IsNullOrEmpty(dependingModule) && !string.IsNullOrEmpty(dependentModule))\n{\n    solver.AddModule(dependingModule);\n    solver.AddDependency(dependingModule, dependentModule);\n}","handlingStrategy":"validation","validationCode":"var known = modules.Select(m => m.ModuleName).ToHashSet();\nforeach (var m in modules)\n{\n    foreach (var d in m.DependsOn ?? Enumerable.Empty<string>())\n    {\n        if (string.IsNullOrWhiteSpace(d) || !known.Contains(d))\n            throw new InvalidOperationException($\"Module '{m.ModuleName}' has invalid dependency '{d}'\");\n    }\n}","typeGuard":"bool IsKnownDependency(string d, ISet<string> known) => !string.IsNullOrWhiteSpace(d) && known.Contains(d);","tryCatchPattern":"try\n{\n    catalog.Validate();\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Dependency solver rejected a module/dependency name: {0}\", ex.Message);\n}","preventionTips":["Validate DependsOn entries against registered ModuleNames before validation","Strip empty strings from DependsOn arrays when parsing config","Add all modules to the solver before resolving dependency edges"],"tags":["argument","empty-string","unknown-module","dependency-solver","prism"],"backgroundTag":"empty-required-field","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}