{"record":{"id":"814113dc71093e5d","repo":"nopSolutions/nopCommerce","slug":"schedule-task-cannot-be-loaded","errorCode":null,"errorMessage":"Schedule task cannot be loaded","messagePattern":"Schedule task cannot be loaded","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/ScheduleTaskController.cs","lineNumber":83,"sourceCode":"    }\n\n    [HttpPost]\n    [CheckPermission(StandardPermission.System.MANAGE_SCHEDULE_TASKS)]\n    public virtual async Task<IActionResult> List(ScheduleTaskSearchModel searchModel)\n    {\n        //prepare model\n        var model = await _scheduleTaskModelFactory.PrepareScheduleTaskListModelAsync(searchModel);\n\n        return Json(model);\n    }\n\n    [HttpPost]\n    [CheckPermission(StandardPermission.System.MANAGE_SCHEDULE_TASKS)]\n    public virtual async Task<IActionResult> TaskUpdate(ScheduleTaskModel model)\n    {\n        //try to get a schedule task with the specified id\n        var scheduleTask = await _scheduleTaskService.GetTaskByIdAsync(model.Id)\n            ?? throw new ArgumentException(\"Schedule task cannot be loaded\");\n\n        //To prevent inject the XSS payload in Schedule tasks ('Name' field), we must disable editing this field, \n        //but since it is required, we need to get its value before updating the entity.\n        if (!string.IsNullOrEmpty(scheduleTask.Name))\n        {\n            model.Name = scheduleTask.Name;\n            ModelState.Remove(nameof(model.Name));\n        }\n\n        if (!ModelState.IsValid)\n            return ErrorJson(ModelState.SerializeErrors());\n\n        if (!scheduleTask.Enabled && model.Enabled)\n            scheduleTask.LastEnabledUtc = DateTime.UtcNow;\n\n        scheduleTask = model.ToEntity(scheduleTask);\n\n        await _scheduleTaskService.UpdateTaskAsync(scheduleTask);","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/ScheduleTaskController.cs#L65-L101","documentation":"Thrown by TaskUpdate (POST, MANAGE_SCHEDULE_TASKS) on ScheduleTaskController when GetTaskByIdAsync(model.Id) returns null. The inline edit on the schedule-tasks grid posts a ScheduleTaskModel; if no task matches model.Id the action cannot proceed and throws. The exception message 'Schedule task cannot be loaded' is generic (no nameof).","triggerScenarios":"Inline-editing a schedule-task row whose underlying task was removed; tampered model.Id; tasks cleared by an uninstall that removed plugin-registered tasks; restored DB without that task.","commonSituations":"Plugin uninstall that deleted its schedule tasks while the grid was open; fixtures; DB restore; concurrent admin edits to the tasks grid.","solutions":["Refresh the schedule-tasks grid and edit a current row.","Confirm the task still exists after plugin install/uninstall cycles.","Make the update idempotent or return ErrorJson when the task is missing.","Validate model.Id > 0 and present before saving edits."],"exampleFix":"// before\nvar scheduleTask = await _scheduleTaskService.GetTaskByIdAsync(model.Id)\n    ?? throw new ArgumentException(\"Schedule task cannot be loaded\");\n\n// after\nvar scheduleTask = await _scheduleTaskService.GetTaskByIdAsync(model.Id);\nif (scheduleTask == null)\n    return ErrorJson(\"Schedule task no longer exists; refresh the list.\");","handlingStrategy":"validation","validationCode":"if (model.Id <= 0) return ErrorJson(\"Invalid task id.\");\nvar task = await _scheduleTaskService.GetTaskByIdAsync(model.Id);\nif (task == null) return ErrorJson(\"Task no longer exists.\");","typeGuard":"// N/A","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"Schedule task cannot be loaded\"))\n{ return ErrorJson(ex.Message); }","preventionTips":["Refresh the tasks grid after plugin install/uninstall.","Validate task existence before saving inline edits.","Avoid concurrent edits to the schedule-tasks grid."],"tags":["nopcommerce","admin-controller","not-found","schedule-task","inline-edit"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}