{"record":{"id":"14899aa89a5d37a6","repo":"dotnetcore/CAP","slug":"cannot-call-getdefaultvalueforparameter-because-no-parameter","errorCode":null,"errorMessage":"Cannot call GetDefaultValueForParameter, because no parameter default values were supplied.","messagePattern":"Cannot call GetDefaultValueForParameter, because no parameter default values were supplied\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP/Internal/ObjectMethodExecutor/ObjectMethodExecutor.cs","lineNumber":130,"sourceCode":"    /// it's a reference type, and you normally create a new instance per call).\n    /// 2. The custom awaiter (whether or not it's a value type, since if it's not, you need a new instance\n    /// of it, and if it is, it will have to be boxed so the calling code can reference it as an object).\n    /// 3. The async result value, if it's a value type (it has to be boxed as an object, since the calling\n    /// code doesn't know what type it's going to be).\n    /// </remarks>\n    /// <param name=\"target\">The object whose method is to be executed.</param>\n    /// <param name=\"parameters\">Parameters to pass to the method.</param>\n    /// <returns>An object that you can \"await\" to get the method return value.</returns>\n    public ObjectMethodExecutorAwaitable ExecuteAsync(object target, object?[]? parameters)\n    {\n        Debug.Assert(_executorAsync != null, \"Async execution is not supported.\");\n        return _executorAsync(target, parameters);\n    }\n\n    public object? GetDefaultValueForParameter(int index)\n    {\n        if (_parameterDefaultValues == null)\n            throw new InvalidOperationException(\n                $\"Cannot call {nameof(GetDefaultValueForParameter)}, because no parameter default values were supplied.\");\n\n        if (index < 0 || index > MethodParameters.Length - 1) throw new ArgumentOutOfRangeException(nameof(index));\n\n        return _parameterDefaultValues[index];\n    }\n\n    private static MethodExecutor GetExecutor(MethodInfo methodInfo, TypeInfo targetTypeInfo)\n    {\n        // Parameters to executor\n        var targetParameter = Expression.Parameter(typeof(object), \"target\");\n        var parametersParameter = Expression.Parameter(typeof(object?[]), \"parameters\");\n\n        // Build parameter list\n        var paramInfos = methodInfo.GetParameters();\n        var parameters = new List<Expression>(paramInfos.Length);\n        for (var i = 0; i < paramInfos.Length; i++)\n        {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP/Internal/ObjectMethodExecutor/ObjectMethodExecutor.cs#L112-L148","documentation":"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.","triggerScenarios":"Thrown at src/DotNetCore.CAP/Internal/ObjectMethodExecutor/ObjectMethodExecutor.cs:130 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Build the ObjectMethodExecutor with the overload that supplies parameter default values (e.g. ObjectMethodExecutor.Create(methodInfo, target, parameterDefaultValues)) so defaults are available.","Avoid calling GetDefaultValueForParameter on executors constructed without default-value information; ensure all arguments are supplied explicitly instead."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}