{"record":{"id":"2950d54487f7e7e6","repo":"PrismLibrary/Prism","slug":"value-cannot-be-null-parameter-modulecatalog","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'moduleCatalog')","messagePattern":"Value cannot be null\\. \\(Parameter 'moduleCatalog'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Modularity/ModuleManager.cs","lineNumber":48,"sourceCode":"    {\n        add => throw new NotSupportedException();\n        remove => throw new NotSupportedException();\n    }\n\n    /// <summary>\n    /// The module initializer.\n    /// </summary>\n    protected IModuleInitializer ModuleInitializer { get; }\n\n    /// <summary>\n    /// Initializes an instance of the <see cref=\"ModuleManager\"/> class.\n    /// </summary>\n    /// <param name=\"moduleInitializer\">Service used for initialization of modules.</param>\n    /// <param name=\"moduleCatalog\">Catalog that enumerates the modules to be loaded and initialized.</param>\n    public ModuleManager(IModuleInitializer moduleInitializer, IModuleCatalog moduleCatalog)\n    {\n        ModuleInitializer = moduleInitializer ?? throw new ArgumentNullException(nameof(moduleInitializer));\n        ModuleCatalog = moduleCatalog ?? throw new ArgumentNullException(nameof(moduleCatalog));\n    }\n\n    /// <summary>\n    /// Initializes the modules marked as <see cref=\"InitializationMode.WhenAvailable\"/> in the <see cref=\"ModuleCatalog\"/>.\n    /// </summary>\n    public void Run()\n    {\n        LoadModulesWhenAvailable();\n    }\n\n    /// <summary>\n    /// Loads and initializes the module in the <see cref=\"IModuleCatalog\"/> with the name <paramref name=\"moduleName\"/>.\n    /// </summary>\n    /// <param name=\"moduleName\">Name of the module requested for initialization.</param>\n    public void LoadModule(string moduleName)\n    {\n        var modules = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);\n        if (modules == null || modules.Count() == 0)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Modularity/ModuleManager.cs#L30-L66","documentation":"The ModuleManager constructor throws ArgumentNullException when either the IModuleInitializer or the IModuleCatalog dependency is null. The catalog enumerates which modules to load and initialize, so a null catalog makes the module system non-functional. This is a fail-fast guard against wiring mistakes in dependency injection.","triggerScenarios":"Constructing ModuleManager directly with `new ModuleManager(initializer, null)` or resolving it from a DI container where IModuleCatalog was never registered, so the container injects null.","commonSituations":"Custom PrismApplication/maui startup code that forgets `containerRegistry.RegisterSingleton<IModuleCatalog, ModuleCatalog>()`; manual instantiation in unit tests; replacing Prism's DI registration pipeline and losing the catalog registration.","solutions":["Register IModuleCatalog with the DI container (e.g. in CreateWindowScope/App: containerRegistry.RegisterSingleton<IModuleCatalog, ModuleCatalog>()) before ModuleManager is resolved.","If constructing manually, pass a concrete ModuleCatalog instance: new ModuleManager(new ModuleInitializer(...), new ModuleCatalog()).","Check ordering: ensure the module catalog is populated (via ConfigureModuleCatalog) before ModuleManager.Run() is invoked."],"exampleFix":"// before\nservices.AddSingleton<ModuleManager>(); // IModuleCatalog never registered -> null\n// after\nservices.AddSingleton<IModuleCatalog, ModuleCatalog>();\nservices.AddSingleton<IModuleInitializer, ModuleInitializer>();\nservices.AddSingleton<ModuleManager>();","handlingStrategy":"validation","validationCode":"var catalog = serviceProvider.GetService<IModuleCatalog>();\nif (catalog is null)\n    throw new InvalidOperationException(\"IModuleCatalog is not registered; register it before resolving ModuleManager.\");\nvar manager = new ModuleManager(initializer, catalog);","typeGuard":"bool IsValidDeps(IModuleInitializer i, IModuleCatalog c) => i is not null && c is not null;","tryCatchPattern":null,"preventionTips":["Always register IModuleCatalog and IModuleInitializer as singletons in the DI container.","Let the DI container construct ModuleManager rather than new-ing it manually.","Write a startup smoke test that resolves ModuleManager to catch missing registrations early."],"tags":["null-argument","dependency-injection","modularity"],"backgroundTag":"null-argument","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"}