{"record":{"id":"13a0c9bc372ff72c","repo":"nopSolutions/nopCommerce","slug":"schedule-task-scheduletask-type-cannot-by-inst","errorCode":null,"errorMessage":"Schedule task ({scheduleTask.Type}) cannot by instantiated","messagePattern":"Schedule task \\((.+?)\\) cannot by instantiated","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/ScheduleTasks/ScheduleTaskRunner.cs","lineNumber":53,"sourceCode":"        _logger = logger;\n        _scheduleTaskService = scheduleTaskService;\n        _storeContext = storeContext;\n    }\n\n    #endregion\n\n    #region Utilities\n\n    /// <summary>\n    /// Initialize and execute task\n    /// </summary>\n    protected virtual async Task PerformTaskAsync(ScheduleTask scheduleTask)\n    {\n        var type = (Type.GetType(scheduleTask.Type) ??\n                    //ensure that it works fine when only the type name is specified (do not require fully qualified names)\n                    AppDomain.CurrentDomain.GetAssemblies()\n                        .Select(a => a.GetType(scheduleTask.Type))\n                        .FirstOrDefault(t => t != null)) ?? throw new Exception($\"Schedule task ({scheduleTask.Type}) cannot by instantiated\");\n\n        object instance = null;\n\n        try\n        {\n            instance = EngineContext.Current.Resolve(type);\n        }\n        catch\n        {\n            // ignored\n        }\n\n        instance ??= EngineContext.Current.ResolveUnregistered(type);\n\n        if (instance is not IScheduleTask task)\n            return;\n\n        scheduleTask.LastStartUtc = DateTime.UtcNow;","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ScheduleTasks/ScheduleTaskRunner.cs#L35-L71","documentation":"Thrown by ScheduleTaskRunner.PerformTaskAsync when the schedule task's type cannot be resolved at runtime. It first tries Type.GetType(scheduleTask.Type), then falls back to scanning all loaded assemblies via AppDomain.CurrentDomain.GetAssemblies().Select(a=>a.GetType(...)). If both yield null, it throws. This means the configured type string does not match any type in any loaded assembly.","triggerScenarios":"A ScheduleTask row references a Type string that is misspelled, namespace-changed, in an assembly that is not loaded, or belongs to a plugin that was uninstalled/disabled. Also triggers after a rename/refactor where the DB still holds the old fully-qualified type name.","commonSituations":"Upgrading nopCommerce and a task type was renamed/moved; uninstalling a plugin whose task row remains in the ScheduleTask table; typo in a custom task's Type column; assembly load failure keeping the plugin's assembly out of the AppDomain.","solutions":["In the database ScheduleTask table, correct the [Type] column to the exact fully-qualified type name that currently exists (use typeof(MyTask).FullName).","Ensure the plugin/assembly containing the task is installed and actually loaded (check loaded assemblies; fix any load errors).","If the task is obsolete, delete the ScheduleTask row rather than leaving a dangling reference.","Verify the type has a public constructor resolvable by the DI container (EngineContext.Current.Resolve)."],"exampleFix":"// before (DB): Type = \"Nop.MyOldNs.SendEmailsTask, Nop.MyOldAssembly\"\n// after  (DB): Type = typeof(MyNewNs.SendEmailsTask).FullName\n//             e.g. \"Nop.MyNewNs.SendEmailsTask, Nop.MyNewAssembly\"","handlingStrategy":"validation","validationCode":"var type = Type.GetType(task.Type)\n    ?? AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType(task.Type)).FirstOrDefault(t => t is not null);\nif (type is null) { logger.Warn($\"Task type not found: {task.Type}\"); /* skip or disable task */ return; }","typeGuard":"static bool IsTaskTypeResolvable(string typeString) =>\n    Type.GetType(typeString) is not null\n    || AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetType(typeString) is not null);","tryCatchPattern":"try { await runner.ExecuteAsync(task); }\ncatch (Exception ex) when (ex.Message.Contains(\"cannot by instantiated\"))\n{ logger.Error($\"Schedule task type unresolved: {task.Type}\", ex); }","preventionTips":["After refactoring/renaming a task type, update the ScheduleTask.Type column.","Run a startup health check that resolves every ScheduleTask.Type and logs failures.","Delete ScheduleTask rows for uninstalled plugins."],"tags":["schedule-tasks","reflection","type-resolution","plugins","database"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}