PrismLibrary/Prism · error · InvalidOperationException

Resources.ConfigurationStoreCannotBeNull

Error message

Resources.ConfigurationStoreCannotBeNull

What it means

ConfigurationModuleCatalog.InnerLoad throws InvalidOperationException when the Store property (the IConfigurationStore used to read module configuration) is null. The catalog loads modules from a configuration section, so without a store it cannot proceed. Prism throws early with a clear message instead of a NullReferenceException later.

Solutions

  1. Set the Store property to a ConfigurationStore instance before calling Load: catalog.Store = new ConfigurationStore();
  2. Register IConfigurationStore/ConfigurationStore in your DI container so the catalog is constructed with it.
  3. Prefer the standard bootstrapper/PrismApplication setup that configures the store automatically via CreateFromConfigurationState.
  4. In tests, assign a fake IConfigurationStore that returns your test module section.

Example fix

// before
var catalog = new ConfigurationModuleCatalog();
catalog.Load();

// after
var catalog = new ConfigurationModuleCatalog { Store = new ConfigurationStore() };
catalog.Load();
Defensive patterns

Strategy: validation

Validate before calling

if (catalog is ConfigurationModuleCatalog cmc && cmc.Store == null)
    throw new InvalidOperationException("ConfigurationModuleCatalog.Store must be set before Load().");

Type guard

static bool HasStore(ConfigurationModuleCatalog c) => c.Store != null;

Try / catch

try { catalog.Load(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ConfigurationStore")) { logger.LogError(ex, "Module catalog configuration store missing"); }

Prevention

When it happens

Trigger: Instantiating ConfigurationModuleCatalog and calling Load() (e.g. via CreateFromConfigurationState) without first assigning a ConfigurationStore, such as when the catalog is created by the container without configuring it.

Common situations: Forgetting to register/set ConfigurationStore when wiring the module catalog manually; using ConfigurationModuleCatalog in tests without a stub store; container registration missing so Store stays null.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/537d3a20c94580ee. Report an issue: GitHub.

Appendix: source

Thrown at src/Wpf/Prism.Wpf/Modularity/ConfigurationModuleCatalog.Desktop.cs:32

        /// </summary>
        public ConfigurationModuleCatalog()
        {
            Store = new ConfigurationStore();
        }

        /// <summary>
        /// Gets or sets the store where the configuration is kept.
        /// </summary>
        public IConfigurationStore Store { get; set; }

        /// <summary>
        /// Loads the catalog from the configuration.
        /// </summary>
        protected override void InnerLoad()
        {
            if (Store == null)
            {
                throw new InvalidOperationException(Resources.ConfigurationStoreCannotBeNull);
            }

            EnsureModulesDiscovered();
        }

        private void EnsureModulesDiscovered()
        {
            ModulesConfigurationSection section = Store.RetrieveModuleConfigurationSection();

            if (section != null)
            {
                foreach (ModuleConfigurationElement element in section.Modules)
                {
                    IList<string> dependencies = new List<string>();

                    if (element.Dependencies.Count > 0)
                    {
                        foreach (ModuleDependencyConfigurationElement dependency in element.Dependencies)

View on GitHub (pinned to 358118cd64)