dotnet/efcore · error · InvalidOperationException

' ' cannot be configured for the parameter ' ' of the…

Error message

'{facet}' cannot be configured for the parameter '{parameter}' of the stored procedure '{sproc}'.

What it means

The Direction facet cannot be configured on a parameter that exists solely to carry the rows-affected count. Rows-affected parameters have a fixed direction dictated by the provider, so SetDirection rejects the call outright via the ForRowsAffected guard.

Solutions

  1. Skip direction configuration for rows-affected parameters; EF sets it implicitly.
  2. Branch on parameter.ForRowsAffected before calling HasDirection.
  3. If you need a real output parameter, map it via a normal parameter, not RowsAffectedParameter().
  4. Audit generic fluent helpers to exclude rows-affected/result columns from per-parameter configuration.

Example fix

// before
foreach (var p in sp.Parameters)
{
    p.HasDirection(ParameterDirection.Output); // throws on rows-affected
}

// after
foreach (var p in sp.Parameters)
{
    if (!p.ForRowsAffected)
    {
        p.HasDirection(ParameterDirection.Output);
    }
}
Defensive patterns

Strategy: validation

Validate before calling

foreach (var p in sp.Parameters)
{
    if (!p.ForRowsAffected)
    {
        p.HasDirection(direction);
    }
}

Type guard

static bool CanConfigureDirection(StoredProcedureParameter p)
    => !p.ForRowsAffected;

Prevention

When it happens

Trigger: Calling .HasDirection(...) or setting Direction on a StoredProcedureParameter whose ForRowsAffected is true (created by RowsAffectedParameter()).

Common situations: Treating a rows-affected parameter like a normal output parameter and adding .HasDirection(Output); applying a generic parameter-configuration loop that sets direction on every parameter including rows-affected ones.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/7a222499cbdcdb00. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Metadata/Internal/StoredProcedureParameter.cs:207

    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual ParameterDirection Direction
    {
        get => _direction ?? ParameterDirection.Input;
        set => SetDirection(value, ConfigurationSource.Explicit);
    }

    /// <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;
    }

View on GitHub (pinned to 3a2006ef56)