{"record":{"id":"947de5396af1942d","repo":"PrismLibrary/Prism","slug":"resources-mustbemodulegroupcatalog","errorCode":null,"errorMessage":"Resources.MustBeModuleGroupCatalog","messagePattern":"Resources\\.MustBeModuleGroupCatalog","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Modularity/IModuleCatalogExtensions.cs","lineNumber":165,"sourceCode":"        /// <param name=\"mode\">The <see cref=\"InitializationMode\"/> to use.</param>\n        /// <typeparam name=\"T\">The <see cref=\"IModule\"/> type parameter.</typeparam>\n        /// <returns>The same <see cref=\"IModuleCatalog\"/> instance with the added module.</returns>\n        public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string name, InitializationMode mode)\n            where T : IModule =>\n            catalog.AddModule(new ModuleInfo(typeof(T), name, mode));\n\n        /// <summary>\n        /// Creates and adds a <see cref=\"ModuleInfoGroup\"/> to the catalog.\n        /// </summary>\n        /// <param name=\"catalog\">The catalog to add the module to.</param>\n        /// <param name=\"initializationMode\">Stage on which the module group to be added will be initialized.</param>\n        /// <param name=\"refValue\">Reference to the location of the module group to be added.</param>\n        /// <param name=\"moduleInfos\">Collection of <see cref=\"ModuleInfo\"/> included in the group.</param>\n        /// <returns>The same <see cref=\"IModuleCatalog\"/> with the added module group.</returns>\n        public static IModuleCatalog AddGroup(this IModuleCatalog catalog, InitializationMode initializationMode, string refValue, params ModuleInfo[] moduleInfos)\n        {\n            if (!(catalog is IModuleGroupsCatalog groupSupport))\n                throw new NotSupportedException(Resources.MustBeModuleGroupCatalog);\n\n            if (moduleInfos == null)\n                throw new ArgumentNullException(nameof(moduleInfos));\n\n            ModuleInfoGroup newGroup = new ModuleInfoGroup\n            {\n                InitializationMode = initializationMode,\n                Ref = refValue\n            };\n\n            foreach (var info in moduleInfos)\n            {\n                newGroup.Add(info);\n            }\n\n            groupSupport.Items.Add(newGroup);\n\n            return catalog;","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Modularity/IModuleCatalogExtensions.cs#L147-L183","documentation":"The AddGroup extension method on IModuleCatalog throws NotSupportedException when the catalog does not implement IModuleGroupsCatalog. Grouped module loading (loading several modules as one initialization group) is only supported by catalogs that implement the grouping interface; plain ModuleCatalog instances are not.","triggerScenarios":"Calling catalog.AddGroup(...) on a ModuleCatalog, ConfigurationModuleCatalog, DirectoryModuleCatalog, or AggregateModuleCatalog instance that does not implement IModuleGroupsCatalog.","commonSituations":"Copy-pasting AddGroup usage from a sample that used a grouping-capable catalog; switching catalogs after migration (e.g. from a custom grouped catalog to the standard ModuleCatalog); NuGet/Prism version change where grouping interfaces moved or narrowed.","solutions":["Use a catalog that implements IModuleGroupsCatalog (or add modules individually with AddModule and matching InitializationMode instead of groups).","Check with `catalog is IModuleGroupsCatalog` before calling AddGroup and fall back to AddModule per module.","Restructure module registration: instead of AddGroup, add each ModuleInfo with the desired WhenAvailable/OnDemand InitializationMode.","If grouping is essential, implement/derive a catalog supporting IModuleGroupsCatalog."],"exampleFix":"// before\nIModuleCatalog catalog = new ModuleCatalog();\ncatalog.AddGroup(InitializationMode.OnDemand, \"GroupA\", moduleInfo1, moduleInfo2);\n\n// after\nif (catalog is IModuleGroupsCatalog grouped)\n    grouped.AddGroup(InitializationMode.OnDemand, \"GroupA\", moduleInfo1, moduleInfo2);\nelse\n{\n    catalog.AddModule(moduleInfo1);\n    catalog.AddModule(moduleInfo2);\n}","handlingStrategy":"type-guard","validationCode":"if (catalog is not IModuleGroupsCatalog)\n    throw new InvalidOperationException(\"AddGroup requires an IModuleGroupsCatalog; use AddModule per module instead.\");","typeGuard":"static bool SupportsGroups(IModuleCatalog c) => c is IModuleGroupsCatalog;","tryCatchPattern":"try { catalog.AddGroup(mode, refValue, modules); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"ModuleGroupCatalog\")) { logger.LogError(ex, \"Catalog does not support module groups\"); }","preventionTips":["Check catalog capabilities before using extension methods that require special interfaces.","Prefer AddModule with InitializationMode when grouping is not essential.","Keep catalog type consistent with the API surface your code uses.","Re-verify extension usage after Prism version upgrades."],"tags":["unsupported-operation","modularity","extension-method","wpf"],"backgroundTag":"unsupported-operation","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"}