dotnet/efcore · error · InvalidOperationException
Unsupported direction '{direction}' was specified for the pa
Error message
Unsupported direction '{direction}' was specified for the parameter '{parameter}' of the stored procedure '{sproc}'. What it means
Thrown by StoredProcedureParameter.SetDirection when the requested ParameterDirection is not valid for that parameter. IsValid rejects ParameterDirection.ReturnValue for all parameters, and ParameterDirection.Output for original-value parameters (ForOriginalValue == true), because output original-value parameters have no meaningful semantics.
Source
Thrown at src/EFCore.Relational/Metadata/Internal/StoredProcedureParameter.cs:214
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ParameterDirection SetDirection(ParameterDirection direction, ConfigurationSource configurationSource)
{
if (ForRowsAffected)
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureParameterInvalidConfiguration(
nameof(Direction), Name, ((IReadOnlyStoredProcedure)StoredProcedure).GetStoreIdentifier()?.DisplayName()));
}
if (!IsValid(direction))
{
throw new InvalidOperationException(
RelationalStrings.StoredProcedureParameterInvalidDirection(
direction, Name, ((IReadOnlyStoredProcedure)StoredProcedure).GetStoreIdentifier()?.DisplayName()));
}
_direction = direction;
_directionConfigurationSource = configurationSource.Max(_directionConfigurationSource);
return direction;
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool IsValid(ParameterDirection direction)View on GitHub (pinned to dbf9771522)
Solutions
- For original-value parameters, keep Direction as Input (the default) or InputOutput — never Output.
- Never use ParameterDirection.ReturnValue; use ReturnsRowsAffected() / the rows-affected API for return-value semantics.
- If you need an output parameter, add it via AddParameter (not AddOriginalValueParameter).
Example fix
// before
var p = s.AddOriginalValueParameter("RowVersion");
p.Direction = ParameterDirection.Output; // throws - original value can't be output
// after
var p = s.AddOriginalValueParameter("RowVersion");
p.Direction = ParameterDirection.Input; Defensive patterns
Strategy: validation
Validate before calling
static void SetDirectionValidated(StoredProcedureParameter p, ParameterDirection direction)
{
if (direction == ParameterDirection.ReturnValue)
throw new InvalidOperationException("ReturnValue is not allowed; use the rows-affected API.");
if (direction == ParameterDirection.Output && p.ForOriginalValue == true)
throw new InvalidOperationException("Original-value parameters cannot be Output.");
p.Direction = direction;
} Type guard
static bool IsValidDirection(StoredProcedureParameter p, ParameterDirection d)
=> d != ParameterDirection.ReturnValue && !(d == ParameterDirection.Output && p.ForOriginalValue == true); Prevention
- Never assign ParameterDirection.ReturnValue via the Direction facet.
- Keep original-value (concurrency) parameters as Input.
When it happens
Trigger: StoredProcedureParameter.cs:212-217: IsValid(direction) is false. Produced by setting an original-value parameter's Direction to Output, or setting any parameter's Direction to ReturnValue.
Common situations: Configuring a concurrency token's original-value parameter as Output; trying to use ReturnValue via the Direction facet instead of the dedicated rows-affected/return-value API; scaffolding then nudging directions.
Related errors
- The parameter for the property '{property}' cannot be added
- The original value parameter for the property '{property}' c
- '{facet}' cannot be configured for the parameter '{parameter
- The stored procedure '{sproc}' cannot be configured to retur
- The rows affected parameter cannot be added to the stored pr
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/bffa6142158edcab.
Report an issue: GitHub.