{"record":{"id":"42d71e0f734f144e","repo":"PrismLibrary/Prism","slug":"resources-directorynotfound-string-format-with-modulepath","errorCode":null,"errorMessage":"Resources.DirectoryNotFound (string.Format with ModulePath)","messagePattern":"Resources\\.DirectoryNotFound \\(string\\.Format with ModulePath\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.net45.cs","lineNumber":37,"sourceCode":"    /// The diretory catalog does not continue to monitor the directory after it has created the initialze catalog.\n    /// </remarks>\n    public class DirectoryModuleCatalog : ModuleCatalog\n    {\n        /// <summary>\n        /// Directory containing modules to search for.\n        /// </summary>\n        public string ModulePath { get; set; }\n\n        /// <summary>\n        /// Drives the main logic of building the child domain and searching for the assemblies.\n        /// </summary>\n        protected override void InnerLoad()\n        {\n            if (string.IsNullOrEmpty(ModulePath))\n                throw new InvalidOperationException(Resources.ModulePathCannotBeNullOrEmpty);\n\n            if (!Directory.Exists(ModulePath))\n                throw new InvalidOperationException(\n                    string.Format(CultureInfo.CurrentCulture, Resources.DirectoryNotFound, ModulePath));\n\n            AppDomain childDomain = BuildChildDomain(AppDomain.CurrentDomain);\n\n            try\n            {\n                List<string> loadedAssemblies = new List<string>();\n\n                var assemblies = (\n                                     from Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()\n                                     where !(assembly is System.Reflection.Emit.AssemblyBuilder)\n                                        && assembly.GetType().FullName != \"System.Reflection.Emit.InternalAssemblyBuilder\"\n                                        // TODO: Do this in a less hacky way... probably never gonna happen\n                                        && !assembly.GetName().Name.StartsWith(\"xunit\")\n                                        && !string.IsNullOrEmpty(assembly.Location)\n                                     select assembly.Location\n                                 );\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.net45.cs#L19-L55","documentation":"DirectoryModuleCatalog (.NET Framework build) throws InvalidOperationException with a formatted DirectoryNotFound message when ModulePath is non-empty but the directory does not exist on disk. The message includes the offending path so the misconfiguration is obvious. Thrown before creating the child AppDomain used for assembly scanning.","triggerScenarios":"Setting DirectoryModuleCatalog.ModulePath to a directory that does not exist (typo, wrong working directory, missing deployment folder) and calling Load().","commonSituations":"ClickOnce/publish deployments where the Modules folder was not copied; relative path resolved against an unexpected working directory (e.g. when run under a test runner or service); path renamed between environments.","solutions":["Verify the directory exists before Load: Directory.Exists(path), create it if appropriate with Directory.CreateDirectory(path).","Use an absolute path (Path.Combine(AppContext.BaseDirectory or AppDomain.CurrentDomain.BaseDirectory, \"Modules\")) instead of a relative one.","Ensure the Modules folder is included in deployment (copy-to-output settings for module projects).","Log the resolved ModulePath at startup to catch environment path drift."],"exampleFix":"// before\ncatalog.ModulePath = @\"Modules\"; // relative, breaks under test runner\n\n// after\ncatalog.ModulePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"Modules\");","handlingStrategy":"validation","validationCode":"if (!Directory.Exists(catalog.ModulePath))\n    Directory.CreateDirectory(catalog.ModulePath); // or fail with a clear message","typeGuard":"static bool ModulePathExists(string path) => !string.IsNullOrEmpty(path) && Directory.Exists(path);","tryCatchPattern":"try { catalog.Load(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"directory\") || ex.Message.Contains(ModulePath)) { logger.LogError(ex, \"Modules directory missing: {Path}\", ModulePath); }","preventionTips":["Resolve with absolute paths based on AppDomain.CurrentDomain.BaseDirectory.","Include the Modules folder in deployment/publish output.","Log the resolved path at startup.","Beware working-directory differences under test runners and services."],"tags":["directory","not-found","path","modularity","wpf"],"backgroundTag":"directory-not-found","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"}