{"record":{"id":"1e9d08c1df6a97bd","repo":"nopSolutions/nopCommerce","slug":"no-store-could-be-loaded","errorCode":null,"errorMessage":"No store could be loaded","messagePattern":"No store could be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Services/Helpers/SyncCodeHelper.cs","lineNumber":301,"sourceCode":"\n    /// <summary>\n    /// Gets the current store\n    /// </summary>\n    /// <returns>Store</returns>\n    public virtual Store GetCurrentStore()\n    {\n        if (_cachedStore != null)\n            return _cachedStore;\n\n        //try to determine the current store by HOST header\n        string host = _httpContextAccessor.HttpContext?.Request.Headers[HeaderNames.Host];\n\n        var allStores = GetAllEntities<Store>(query => query.OrderBy(s => s.DisplayOrder).ThenBy(s => s.Id), _ => default, includeDeleted: false);\n        var store = allStores\n            .FirstOrDefault(s => _storeService.ContainsHostValue(s, host))\n            ?? allStores.FirstOrDefault();\n\n        _cachedStore = store ?? throw new Exception(\"No store could be loaded\");\n\n        return _cachedStore;\n    }\n\n    #endregion\n\n    #endregion\n}","sourceCodeStart":283,"sourceCodeEnd":309,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Helpers/SyncCodeHelper.cs#L283-L309","documentation":"Thrown by SyncCodeHelper.GetCurrentStore when no Store can be resolved: there are zero non-deleted stores in the database, and neither the Host-header match nor the fallback (first store) returns a store. nopCommerce requires at least one active store for almost every request, so an empty store table is a fatal configuration error.","triggerScenarios":"Calling GetCurrentStore when GetAllEntities<Store>(..., includeDeleted: false) returns an empty list — i.e. the store table has no non-deleted rows. The Host-header lookup and the allStores.FirstOrDefault() fallback both return null, so the cached store assignment throws.","commonSituations":"Fresh install where the seed store was never created; the only store was soft-deleted; a DB restore/migration dropped store rows; a multi-tenant schema mismatch returns nothing; running a background job/CLI with no store context and an empty store table.","solutions":["Insert or un-delete at least one Store row in Configuration > Stores (or directly in the DB), then restart the app.","If a store was accidentally deleted, restore it from a backup or re-run the database seed.","Verify the connection string points at the intended database and the Store table is populated.","For background/CLI contexts, ensure the host is set so the Host-header match resolves, or seed a default store."],"exampleFix":"// before — no stores in DB, GetCurrentStore() throws\nvar store = _storeContext.GetCurrentStore();\n\n// after — ensure a store exists before resolving\nvar stores = await _storeService.GetAllStoresAsync();\nif (!stores.Any())\n    throw new InvalidOperationException(\"No store configured. Create at least one store in Configuration > Stores.\");\nvar store = _storeContext.GetCurrentStore();","handlingStrategy":"validation","validationCode":"// Ensure at least one non-deleted store exists before resolving the current store\nvar stores = await _storeService.GetAllStoresAsync();\nif (!stores.Any())\n    throw new InvalidOperationException(\"No store configured. Create at least one store in Configuration > Stores.\");\nvar store = _storeContext.GetCurrentStore();","typeGuard":null,"tryCatchPattern":"try { store = _storeContext.GetCurrentStore(); }\ncatch (Exception ex) when (ex.Message == \"No store could be loaded\")\n{ /* seed/un-delete a store or fix the DB connection, then retry; treat as fatal bootstrap error */ }","preventionTips":["Never run with zero stores; seed a default store during installation.","After a DB restore/migration, assert the Store table has at least one non-deleted row.","For background/CLI jobs, ensure a host is set or a default store is seeded so resolution succeeds."],"tags":["store","configuration","multistore","bootstrap","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}