OrchardCMS/OrchardCore · error · InvalidOperationException
The specified activity type is not registered.
Error message
The specified activity type is not registered.
What it means
Thrown by WorkflowOptions.UnregisterActivityType when the given activity Type is not present in the ActivityDictionary. The options container tracks registered workflow activity types, and unregistering an unknown type is treated as a programming error.
Solutions
- Guard with WorkflowOptions' dictionary state (or a ContainsKey check via the same options instance) before unregistering.
- Only unregister types your own module registered, in the reverse order of registration.
- Catch InvalidOperationException and ignore the already-unregistered case.
- Refactor registration bookkeeping to be idempotent.
Example fix
// before
options.UnregisterActivityType(typeof(MyActivity));
// after
if (options.ActivityDictionary.ContainsKey(typeof(MyActivity))) { options.UnregisterActivityType(typeof(MyActivity)); } Defensive patterns
Strategy: validation
Validate before calling
if (options.ActivityDictionary.ContainsKey(typeof(MyActivity))) { options.UnregisterActivityType(typeof(MyActivity)); } Type guard
bool IsRegistered(WorkflowOptions o, Type t) => o.ActivityDictionary.ContainsKey(t);
Try / catch
try { options.UnregisterActivityType(typeof(MyActivity)); }
catch (InvalidOperationException) { /* already unregistered; ignore */ } Prevention
- Track what your module registered and unregister exactly that
- Make registration/unregistration pairs idempotent
- Check module disable ordering across dependent features
- Avoid unregistering base/derived types interchangeably
When it happens
Trigger: Calling UnregisterActivityType for a type that was never registered via AddActivityType, or calling it twice; using a derived/base type mismatch since lookup is by exact Type key.
Common situations: Module shutdown/teardown code that unregisters activities possibly never added; feature disable ordering where another module already unregistered the type; typos or refactors renaming activity classes.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot add model validation errors when there's no Updater…
- Cannot add model validation errors when there's no Updater…
- Cannot add model validation errors when there's no Updater…
- 'IOptionsUpdateNotifier' can only be used from an active…
- The 'CreateContentTask' can't create the content item as it…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/9783225bead7cb85.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Workflows.Abstractions/Options/WorkflowOptions.cs:40
{
if (driverType != null)
{
value.DriverTypes.Add(driverType);
}
}
else
{
ActivityDictionary.Add(activityType, new ActivityRegistration(activityType, driverType));
}
return this;
}
public WorkflowOptions UnregisterActivityType(Type activityType)
{
if (!ActivityDictionary.ContainsKey(activityType))
{
throw new InvalidOperationException("The specified activity type is not registered.");
}
ActivityDictionary.Remove(activityType);
return this;
}
public bool IsActivityRegistered(Type activityType)
{
return ActivityDictionary.ContainsKey(activityType);
}
}
public static class WorkflowOptionsExtensions
{
public static WorkflowOptions RegisterActivityType<T>(this WorkflowOptions options)
{
return options.RegisterActivity(typeof(T));
}View on GitHub (pinned to 4306c0717f)