dotnetcore/CAP · error · InvalidOperationException

Cannot call GetDefaultValueForParameter, because no…

Error message

Cannot call GetDefaultValueForParameter, because no parameter default values were supplied.

What it means

A state guard in ObjectMethodExecutor.GetDefaultValueForParameter: the executor was created without parameter default-value metadata (the array of defaults collected from the method's parameters at construction), yet someone asked it to supply the default value for a parameter. The faulty input is a parameter index whose default cannot be served because none were captured — typically an executor built via a factory overload that skips default-value extraction, then invoked on a method that has optional parameters.

Solutions

  1. Build the ObjectMethodExecutor with the overload that supplies parameter default values (e.g. ObjectMethodExecutor.Create(methodInfo, target, parameterDefaultValues)) so defaults are available.
  2. Avoid calling GetDefaultValueForParameter on executors constructed without default-value information; ensure all arguments are supplied explicitly instead.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/DotNetCore.CAP/Internal/ObjectMethodExecutor/ObjectMethodExecutor.cs:130 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14). Data as JSON: /api/errors/14899aa89a5d37a6. Report an issue: GitHub.

Appendix: source

Thrown at src/DotNetCore.CAP/Internal/ObjectMethodExecutor/ObjectMethodExecutor.cs:130

    /// it's a reference type, and you normally create a new instance per call).
    /// 2. The custom awaiter (whether or not it's a value type, since if it's not, you need a new instance
    /// of it, and if it is, it will have to be boxed so the calling code can reference it as an object).
    /// 3. The async result value, if it's a value type (it has to be boxed as an object, since the calling
    /// code doesn't know what type it's going to be).
    /// </remarks>
    /// <param name="target">The object whose method is to be executed.</param>
    /// <param name="parameters">Parameters to pass to the method.</param>
    /// <returns>An object that you can "await" to get the method return value.</returns>
    public ObjectMethodExecutorAwaitable ExecuteAsync(object target, object?[]? parameters)
    {
        Debug.Assert(_executorAsync != null, "Async execution is not supported.");
        return _executorAsync(target, parameters);
    }

    public object? GetDefaultValueForParameter(int index)
    {
        if (_parameterDefaultValues == null)
            throw new InvalidOperationException(
                $"Cannot call {nameof(GetDefaultValueForParameter)}, because no parameter default values were supplied.");

        if (index < 0 || index > MethodParameters.Length - 1) throw new ArgumentOutOfRangeException(nameof(index));

        return _parameterDefaultValues[index];
    }

    private static MethodExecutor GetExecutor(MethodInfo methodInfo, TypeInfo targetTypeInfo)
    {
        // Parameters to executor
        var targetParameter = Expression.Parameter(typeof(object), "target");
        var parametersParameter = Expression.Parameter(typeof(object?[]), "parameters");

        // Build parameter list
        var paramInfos = methodInfo.GetParameters();
        var parameters = new List<Expression>(paramInfos.Length);
        for (var i = 0; i < paramInfos.Length; i++)
        {

View on GitHub (pinned to e52b8508e5)