{"record":{"id":"8dd2c9efe6c7351b","repo":"OrchardCMS/OrchardCore","slug":"cannot-add-model-validation-errors-when-there-s-no-updater","errorCode":null,"errorMessage":"Cannot add model validation errors when there's no Updater present.","messagePattern":"Cannot add model validation errors when there's no Updater present\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Forms/Workflows/Activities/AddModelValidationErrorTask.cs","lineNumber":45,"sourceCode":"    public string Key\n    {\n        get => GetProperty<string>();\n        set => SetProperty(value);\n    }\n\n    public string ErrorMessage\n    {\n        get => GetProperty<string>();\n        set => SetProperty(value);\n    }\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Done\"]);\n\n    public override ActivityExecutionResult Execute(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        var updater = _updateModelAccessor.ModelUpdater\n            ?? throw new InvalidOperationException(\"Cannot add model validation errors when there's no Updater present.\");\n\n        updater.ModelState.AddModelError(Key, ErrorMessage);\n\n        return Outcome(\"Done\");\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":52,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Forms/Workflows/Activities/AddModelValidationErrorTask.cs#L27-L52","documentation":"AddModelValidationErrorTask requires an IUpdateModel instance (via IUpdateModelAccessor) to record validation errors against. When the workflow executes outside a request context that provides an Updater (e.g. background execution), the accessor is null and the task throws InvalidOperationException.","triggerScenarios":"A workflow containing AddModelValidationErrorTask runs without an active model-binding updater, e.g. triggered by an API call, background task, or non-form HTTP request where no IUpdateModel was registered.","commonSituations":"Reusing a form-validation workflow in a context without a rendered form (REST call, scheduled workflow, tenant background job); calling the workflow during setup or from a shell where UpdateModelAccessor was never populated.","solutions":["Ensure the workflow only runs in the context of an HTTP form submission (start with ValidateForm/submit events).","Inject or register an IUpdateModelAccessor with a valid ModelUpdater for programmatic execution.","Add a guard/condition before the task so it is skipped when no Updater exists.","Replace model-validation error reporting with workflow logging/outcomes if running headlessly."],"exampleFix":"// before: task runs in a background workflow with no updater\n// after: start the workflow only from form submission events,\n// or in code: services.AddScoped<IUpdateModelAccessor>(_ => new DefaultUpdateModelAccessor(updater));","handlingStrategy":"try-catch","validationCode":"var updater = httpContextAccessor.HttpContext?.RequestServices.GetService<IUpdateModelAccessor>()?.ModelUpdater;\nif (updater is null) return; // skip model-error task outside form context","typeGuard":"var updater = _updateModelAccessor.ModelUpdater;\nif (updater is null) return;","tryCatchPattern":"try { await workflowManager.RunWorkflowAsync(...); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"no Updater present\")) { logger.LogWarning(\"Workflow ran without an Updater; model validation skipped\"); }","preventionTips":["Start model-error workflows only from form submission events.","Register IUpdateModelAccessor when invoking workflows programmatically.","Audit workflows for model-state tasks before triggering them headlessly."],"tags":["workflows","forms","validation"],"backgroundTag":"missing-dependency","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}