elsa-workflows/elsa-core · error · InvalidOperationException
Storage unit ' ' was not declared by schema ' '.
Error message
Storage unit '{policy.StorageUnit}' was not declared by schema '{schema.Name}'. What it means
PhysicalizationPolicyValidator.GetStorageUnit looks up policy.StorageUnit by exact name in schema.StorageUnits. If no declared storage unit matches, it throws, because a physicalization policy can only target a storage unit the schema explicitly declares.
Solutions
- Set policy.StorageUnit to the exact Name of a storage unit declared in the schema.
- Update the schema to declare the storage unit referenced by the policy.
- Regenerate/align policy configuration with the current schema definitions after renames.
Example fix
// before policy.StorageUnit = "WorkflowInstance"; // schema declares "WorkflowInstances" // after policy.StorageUnit = "WorkflowInstances";
Defensive patterns
Strategy: validation
Validate before calling
if (!schema.StorageUnits.Any(u => u.Name == policy.StorageUnit))
throw new InvalidOperationException($"Storage unit '{policy.StorageUnit}' is not declared by schema '{schema.Name}'."); Try / catch
try { var unit = PhysicalizationPolicyValidator.GetStorageUnit(schema, policy); }
catch (InvalidOperationException ex) when (ex.Message.Contains("was not declared by schema")) { /* fix policy or schema */ } Prevention
- Reference storage unit names from constants shared with the schema builder.
- Regenerate policies whenever schema names change.
- Keep policy config and schema in the same repo/commit.
When it happens
Trigger: Calling GetStorageUnit (directly or via SqlitePhysicalizationPlanner.Plan) with a StoragePhysicalizationPolicy whose StorageUnit name does not match any storage unit name in the schema — typos, renamed units, or policies copied from another schema.
Common situations: Renaming a table in the schema builder without updating physicalization policies; policy defined in a separate config file drifting from code-defined schema; case sensitivity mismatches (comparison is exact).
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Physicalized index ' ' references undeclared field ' ' on…
- AlterationFaultCodes.PlanNotFound
- AlterationFaultCodes.PlanNotFound
- MongoDB physicalization supports dedicated document…
- Runtime entity definition
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/385f2344330c9db4.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Persistence.VNext/Physicalization/PhysicalizationPolicyValidator.cs:12
using Elsa.Persistence.VNext;
namespace Elsa.Persistence.VNext.Physicalization;
public static class PhysicalizationPolicyValidator
{
public static PersistenceStorageUnit GetStorageUnit(PersistenceSchema schema, StoragePhysicalizationPolicy policy)
{
var storageUnit = schema.StorageUnits.SingleOrDefault(x => x.Name == policy.StorageUnit);
if (storageUnit == null)
throw new InvalidOperationException($"Storage unit '{policy.StorageUnit}' was not declared by schema '{schema.Name}'.");
var fields = storageUnit.Fields.Select(x => x.Name).ToHashSet(StringComparer.Ordinal);
foreach (var index in policy.Indexes)
{
var missingField = index.Fields.FirstOrDefault(field => !fields.Contains(field));
if (missingField != null)
throw new InvalidOperationException($"Physicalized index '{index.Name}' references undeclared field '{missingField}' on storage unit '{storageUnit.Name}'.");
}
return storageUnit;
}
}
View on GitHub (pinned to fe9217bdfa)