{"record":{"id":"8caf9146533c7520","repo":"nopSolutions/nopCommerce","slug":"can-t-get-nameof-istorecontext-implementation-f","errorCode":null,"errorMessage":"Can't get {nameof(IStoreContext)} implementation from the scope","messagePattern":"Can't get (.+?) implementation from the scope","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Services/ScheduleTasks/TaskScheduler.cs","lineNumber":63,"sourceCode":"    /// </summary>\n    /// <returns>A task that represents the asynchronous operation</returns>\n    public virtual async Task InitializeAsync()\n    {\n        if (!DataSettingsManager.IsDatabaseInstalled())\n            return;\n\n        if (_taskThreads.Any())\n            return;\n\n        using var scope = _serviceScopeFactory.CreateScope();\n        var scheduleTaskService = scope.ServiceProvider.GetService<IScheduleTaskService>() ?? throw new NullReferenceException($\"Can't get {nameof(IScheduleTaskService)} implementation from the scope\");\n\n        //initialize and start schedule tasks\n        var scheduleTasks = (await scheduleTaskService.GetAllTasksAsync())\n            .OrderBy(x => x.Seconds)\n            .ToList();\n\n        var storeContext = scope.ServiceProvider.GetService<IStoreContext>() ?? throw new NullReferenceException($\"Can't get {nameof(IStoreContext)} implementation from the scope\");\n\n        var store = await storeContext.GetCurrentStoreAsync();\n\n        var scheduleTaskUrl = $\"{store.Url.TrimEnd('/')}/{NopTaskDefaults.ScheduleTaskPath}\";\n        var timeout = _appSettings.Get<CommonConfig>().ScheduleTaskRunTimeout;\n\n        foreach (var scheduleTask in scheduleTasks)\n        {\n            var taskThread = new TaskThread(scheduleTask, scheduleTaskUrl, timeout)\n            {\n                Seconds = scheduleTask.Seconds\n            };\n\n            //sometimes a task period could be set to several hours (or even days)\n            //in this case a probability that it'll be run is quite small (an application could be restarted)\n            //calculate time before start an interrupted task\n            if (scheduleTask.LastStartUtc.HasValue)\n            {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ScheduleTasks/TaskScheduler.cs#L45-L81","documentation":"Thrown by TaskScheduler.InitializeAsync when scope.ServiceProvider.GetService<IStoreContext>() returns null, as a NullReferenceException with a descriptive message. It is resolved right after IScheduleTaskService, so if you reach this line the service scope works but IStoreContext specifically is not registered/resolvable.","triggerScenarios":"During scheduler init, after tasks load successfully, when the DI container cannot produce IStoreContext. Often caused by a registration extension for the store context failing or a custom IStoreContext implementation whose constructor dependencies cannot be satisfied.","commonSituations":"Multi-store customization replaces IStoreContext with a custom implementation whose dependencies throw during construction (GetService swallows constructor exceptions and returns null); a plugin dependency registrar overwrote IStoreContext with an unresolvable type; partial deployment.","solutions":["Check the application log for constructor exceptions from your IStoreContext implementation (GetService returns null on construction failure).","Confirm IStoreContext is registered exactly once with a resolvable implementation and all its constructor dependencies are registered.","Remove or fix any custom IDependencyRegistrar that re-registers IStoreContext incorrectly.","Restore the default store context registration if it was inadvertently removed."],"exampleFix":"// before: a custom registrar overwrites with an unresolvable impl\nservices.AddTransient<IStoreContext, MyBrokenStoreContext>();\n// after: ensure MyBrokenStoreContext ctor deps are registered, or revert:\nservices.AddScoped<IStoreContext, WebStoreContext>();","handlingStrategy":"try-catch","validationCode":"using var scope = _serviceScopeFactory.CreateScope();\nvar ctx = scope.ServiceProvider.GetService<IStoreContext>();\nif (ctx is null) { logger.Critical(\"IStoreContext unresolved; check registrations.\"); return; }","typeGuard":null,"tryCatchPattern":"try { await _taskScheduler.InitializeAsync(); }\ncatch (NullReferenceException ex) when (ex.Message.Contains(nameof(IStoreContext)))\n{ logger.Critical(\"IStoreContext could not be constructed; inspect ctor deps.\", ex); }","preventionTips":["Ensure IStoreContext constructor dependencies are all registered.","Avoid re-registering IStoreContext with an implementation that can throw in its ctor.","Smoke-test service resolution for IStoreContext after startup."],"tags":["schedule-tasks","dependency-injection","startup","multi-store","di-resolution"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}