OrchardCMS/OrchardCore · error · InvalidOperationException

Cannot add model validation errors when there's no Updater…

Error message

Cannot add model validation errors when there's no Updater present.

What it means

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.

Solutions

  1. Ensure the workflow only runs in the context of an HTTP form submission (start with ValidateForm/submit events).
  2. Inject or register an IUpdateModelAccessor with a valid ModelUpdater for programmatic execution.
  3. Add a guard/condition before the task so it is skipped when no Updater exists.
  4. Replace model-validation error reporting with workflow logging/outcomes if running headlessly.

Example fix

// before: task runs in a background workflow with no updater
// after: start the workflow only from form submission events,
// or in code: services.AddScoped<IUpdateModelAccessor>(_ => new DefaultUpdateModelAccessor(updater));
Defensive patterns

Strategy: try-catch

Validate before calling

var updater = httpContextAccessor.HttpContext?.RequestServices.GetService<IUpdateModelAccessor>()?.ModelUpdater;
if (updater is null) return; // skip model-error task outside form context

Type guard

var updater = _updateModelAccessor.ModelUpdater;
if (updater is null) return;

Try / catch

try { await workflowManager.RunWorkflowAsync(...); } catch (InvalidOperationException ex) when (ex.Message.Contains("no Updater present")) { logger.LogWarning("Workflow ran without an Updater; model validation skipped"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/8dd2c9efe6c7351b. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Forms/Workflows/Activities/AddModelValidationErrorTask.cs:45

    public string Key
    {
        get => GetProperty<string>();
        set => SetProperty(value);
    }

    public string ErrorMessage
    {
        get => GetProperty<string>();
        set => SetProperty(value);
    }

    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
        => Outcome(S["Done"]);

    public override ActivityExecutionResult Execute(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
    {
        var updater = _updateModelAccessor.ModelUpdater
            ?? throw new InvalidOperationException("Cannot add model validation errors when there's no Updater present.");

        updater.ModelState.AddModelError(Key, ErrorMessage);

        return Outcome("Done");
    }
}

View on GitHub (pinned to 4306c0717f)