{"record":{"id":"c4a51ef367959e57","repo":"PrismLibrary/Prism","slug":"resources-modulepathcannotbenullorempty-c4a51e","errorCode":null,"errorMessage":"Resources.ModulePathCannotBeNullOrEmpty","messagePattern":"Resources\\.ModulePathCannotBeNullOrEmpty","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.netcore.cs","lineNumber":36,"sourceCode":"    /// Assemblies are loaded into a new application domain with ReflectionOnlyLoad.  The application domain is destroyed\n    /// once the assemblies have been discovered.\n    ///\n    /// The directory catalog does not continue to monitor the directory after it has created the initialize 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 = 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                        && !String.IsNullOrEmpty(assembly.Location)\n                    select assembly.Location\n                );","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.netcore.cs#L18-L54","documentation":"DirectoryModuleCatalog (.NET Core/.NET 5+ build) throws InvalidOperationException when ModulePath is null or empty. As in the .NET Framework variant, this catalog discovers modules by scanning a directory, so a valid path is required. The check is the first statement of InnerLoad, before any file-system access.","triggerScenarios":"Constructing a DirectoryModuleCatalog on .NET Core and calling Load() without assigning ModulePath, or assigning an empty string (e.g. from a missing config value).","commonSituations":"Empty appsettings/section value for the modules directory; forgetting the property when migrating from a config-based catalog; DI-constructed catalog where path injection was skipped.","solutions":["Assign ModulePath before Load: catalog.ModulePath = Path.Combine(AppContext.BaseDirectory, \"Modules\");","If the path comes from IConfiguration, validate it is non-empty at startup (fail fast).","Default to the application base directory plus 'Modules' when no explicit path is configured.","Add a unit test that builds the catalog the same way as production to surface the misconfiguration early."],"exampleFix":"// before\nvar catalog = new DirectoryModuleCatalog(); // ModulePath never set\ncatalog.Load();\n\n// after\nvar catalog = new DirectoryModuleCatalog { ModulePath = Path.Combine(AppContext.BaseDirectory, \"Modules\") };\ncatalog.Load();","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(catalog.ModulePath))\n    catalog.ModulePath = Path.Combine(AppContext.BaseDirectory, \"Modules\");","typeGuard":"static bool HasModulePath(DirectoryModuleCatalog c) => !string.IsNullOrWhiteSpace(c.ModulePath);","tryCatchPattern":"try { catalog.Load(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ModulePath\")) { logger.LogError(ex, \"ModulePath not configured\"); }","preventionTips":["Always initialize ModulePath before Load().","Validate appsettings values for the modules directory at startup.","Default to AppContext.BaseDirectory-based path.","Unit-test the catalog setup used in production."],"tags":["directory","modularity","path","netcore"],"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"}