0

I got the below exception when implementing the POST method

[2022-06-17T07:14:41.723Z] Executed 'Functions.AuthenticateHttpTrigger' (Failed, Id=12bb7c91-4030-4090-a2fe-ec205702c662, Duration=424954ms)
[2022-06-17T07:14:41.726Z] System.Private.CoreLib: Exception while executing function: Functions.AuthenticateHttpTrigger. System.Private.CoreLib: Result: Failure
Exception: System.InvalidOperationException: Duplicate binding call detected. Input parameters can only be bound to arguments once. Use the InputArguments property to inspect values.
[2022-06-17T07:14:41.727Z]    at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 29
[2022-06-17T07:14:41.728Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 37
[2022-06-17T07:14:41.729Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13

Have you encountered an issue like that? please advise.

Thanks in advance.

============================================

EDIT

Here is my function definition

[AllowAnonymous]
[Function(nameof(AuthenticateHttpTrigger))]
[OpenApiOperation(operationId: nameof(AuthenticateHttpTrigger), Description = "Authenticate")]
[OpenApiRequestBody(contentType: Constants.CommonResponseContentType, bodyType: typeof(AuthenticationRequest))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: Constants.CommonResponseContentType, bodyType: typeof(AuthenticationResponse), Description = "The OK response")]
public async Task<HttpResponseData> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "authenticate")] HttpRequestData req, FunctionContext executionContext)
{
    try
    {
        _logTrace.Add(LogLevel.Info, $"{nameof(AuthenticateHttpTrigger)} - AUTHENTICATE START", new { });
        var requestUser = executionContext.Features.Get<JwtPrincipalFeature>()?.User;
        var requestData = await req.GetBodyAsync<AuthenticationRequest>();
        var addUserCommand = new AuthenticateCommand
        {
            RequestUser = requestUser,
            Data = requestData,
            LogTrace = _logTrace
        };

        return await _httpFunctionExecutor.ExecuteAsync(async () =>
        {
            var result = await _mediator.Send(addUserCommand);

            _logTrace.Add(LogLevel.Info, $"{nameof(AuthenticateHttpTrigger)} - AUTHENTICATE END ", new { result });

            return result.Success
                ? CreateResponse(HttpStatusCode.OK, req, result.Data)
                : CreateResponse(HttpStatusCode.UnprocessableEntity, req, null);
        }, req);
    }
    catch (Exception e)
    {
        _logTrace.AddError(e);
        return CreateResponse(HttpStatusCode.UnprocessableEntity, req, null);
    }
    finally
    {
        _logTrace.Flush();
    }
}
Mohsen Esmailpour
  • 11,224
  • 3
  • 45
  • 66
jack.pop
  • 683
  • 2
  • 6
  • 21
  • Share your function definition. – Tanveer Badar Jun 17 '22 at 07:22
  • 1
    @TanveerBadar I have just edited the question and put a detailed function definition. Thanks. – jack.pop Jun 17 '22 at 07:33
  • I managed to solve the problem by breaking the middleware. Something like this ```if (targetMethod?.GetCustomAttribute(typeof(AllowAnonymousAttribute), false) is AllowAnonymousAttribute) { await next(context); return; }``` – jack.pop Jun 20 '22 at 08:48

1 Answers1

1

System.Private.CoreLib: Exception while executing function: Functions.AuthenticateHttpTrigger. System.Private.CoreLib: Result: Failure Exception: System.InvalidOperationException: Duplicate binding call detected. Input parameters can only be bound to arguments once. Use the InputArguments property to inspect values.

The Error message shows that in your function execution the input Arguments are duplicated. You have to avoid the duplication of InputArgument it should be bound once while executing the function.

I hope you fixed the same way by using GetCustomAttribute.

if(targetMethod?.GetCustomAttribute(typeof(AllowAnonymousAttribute), false) is AllowAnonymousAttribute) 
{ 
    await next(context); return; 
}

Refer the blog for more information

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15
  • Yes, I use middleware for authorization and authentication. If I bypass the validation, I put the `return` statement to fix the issue. Thansk – jack.pop Jun 21 '22 at 07:09