{"record":{"id":"bace7bc11edbc0e0","repo":"nopSolutions/nopCommerce","slug":"no-store-could-be-loaded-bace7b","errorCode":null,"errorMessage":"No store could be loaded","messagePattern":"No store could be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Presentation/Nop.Web.Framework/WebStoreContext.cs","lineNumber":69,"sourceCode":"\r\n    #region Properties\r\n\r\n    /// <summary>\r\n    /// Gets the current store\r\n    /// </summary>\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    public virtual async Task<Store> GetCurrentStoreAsync()\r\n    {\r\n        if (_cachedStore != null)\r\n            return _cachedStore;\r\n\r\n        //try to determine the current store by HOST header\r\n        string host = _httpContextAccessor.HttpContext?.Request.Headers[HeaderNames.Host];\r\n\r\n        var allStores = await _storeService.GetAllStoresAsync();\r\n        var store = allStores.FirstOrDefault(s => _storeService.ContainsHostValue(s, host)) ?? allStores.FirstOrDefault();\r\n\r\n        _cachedStore = store ?? throw new Exception(\"No store could be loaded\");\r\n\r\n        return _cachedStore;\r\n    }\r\n\r\n    /// <summary>\r\n    /// Gets active store scope configuration\r\n    /// </summary>\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    public virtual async Task<int> GetActiveStoreScopeConfigurationAsync()\r\n    {\r\n        if (_cachedActiveStoreScopeConfiguration.HasValue)\r\n            return _cachedActiveStoreScopeConfiguration.Value;\r\n\r\n        //ensure that we have 2 (or more) stores\r\n        if ((await _storeService.GetAllStoresAsync()).Count > 1)\r\n        {\r\n            //do not inject IWorkContext via constructor because it'll cause circular references\r\n            var currentCustomer = await EngineContext.Current.Resolve<IWorkContext>().GetCurrentCustomerAsync();\r","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web.Framework/WebStoreContext.cs#L51-L87","documentation":"Thrown by WebStoreContext.GetCurrentStoreAsync when it cannot resolve ANY store: it tries the Host header match, then the first store overall, and if GetAllStoresAsync returns an empty list it throws a generic Exception. This is a fatal bootstrap/config error — the instance has zero Store records.","triggerScenarios":"Any request reaching the storefront framework when the Store table is empty. Triggered by a fresh DB with no seed stores, a botched migration that wiped Store rows, or a multi-tenant DB where the tenant filter excludes all stores.","commonSituations":"Fresh install where the seed data didn't run; a restore of a DB backup that dropped the Store table; dev environment where someone truncated stores; misconfigured tenant/scope filter.","solutions":["Seed at least one Store row (run the nopCommerce upgrade/install seed, or insert a default store record).","Confirm the connection string points at the intended DB and the Store table has rows.","If using a custom IStoreService, verify its GetAllStoresAsync is not silently filtering everything out.","Temporarily set a known store so the host-header lookup resolves instead of relying on the fallback."],"exampleFix":"// before\n_cachedStore = store ?? throw new Exception(\"No store could be loaded\");\n\n// after (fail with actionable diagnostics)\nif (store == null)\n    throw new NopException(\"No store could be loaded. Ensure the Store table has at least one row and the Host header matches a configured store.\");\n_cachedStore = store;\n","handlingStrategy":"validation","validationCode":"// Health check: fail fast at startup if no stores exist.\nvar storeCount = (await _storeService.GetAllStoresAsync()).Count;\nif (storeCount == 0)\n    throw new InvalidOperationException(\"No stores configured. Seed the Store table before serving traffic.\");","typeGuard":"// Ensure a store is resolvable before any code path that needs one.\nstatic bool HasAnyStore(IStoreService svc) => svc.GetAllStoresAsync().GetAwaiter().GetResult().Any();","tryCatchPattern":"// Let bootstrap/runtime surface this clearly; usually not caught per-request.\ntry { var store = await _storeContext.GetCurrentStoreAsync(); }\ncatch (Exception ex) when (ex.Message == \"No store could be loaded\")\n{\n    _logger.Critical(ex, \"Store table empty or Host header unmatched\");\n    throw; // rethrow; this is fatal and must be fixed at the config layer.\n}","preventionTips":["Always run the install/upgrade seed so at least one Store row exists.","Verify the connection string targets the right DB before going live.","For multi-tenant setups, confirm the tenant filter doesn't exclude every store.","Add a startup health check asserting Store count > 0."],"tags":["nopcommerce","store-context","bootstrap","configuration","fatal"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}