Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
737 stars 358 forks source link

Cannot bind parameter '$return' to type IActionResult #3061

Open andremiranda-act3d opened 6 months ago

andremiranda-act3d commented 6 months ago

Hi! When executing ServiceBusTrigger or TimeTrigger Functions, I got this exception:

The 'CrmOrderSubscriptionFunction' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'CrmOrderSubscriptionFunction'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type IActionResult&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Before, all the Functions were returning a Task and they were working just fine. But, many of these Functions call to some external apis and we would like to get these calls responses and make the Functions return them. Otherwise, the Functions are always returning a 200 (or at maximum a 500 if it is something out of our control).

We have 1 HttpTrigger function that is not throwing this exception. Only the ServiceBus and TimeTrigger ones.

We are using .NET 6. Don't know if the host.json is necessary, but currently in VS is like this:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "Default": "Debug"
    }
  },
  "extensions": {
    "queues": {
      "maxPollingInterval": "00:00:02",
      "visibilityTimeout": "00:00:30",
      "batchSize": 1,
      "maxDequeueCount": 2,
      "newBatchThreshold": 0
    },
    "serviceBus": {
      "messageHandlerOptions": {
        "maxConcurrentCalls": 2
      },
      "sessionHandlerOptions": {
        "maxConcurrentSessions": 1
      }
    }
  }
}
bhagyshricompany commented 6 months ago

Thanks for reporting please share the all repro steps

andremiranda-act3d commented 6 months ago

Just setting up a ServiceBusTriggered or TimerTrigger Function like below and the exception will be thrown at startup:

 [FunctionName(FunctionName)]
    public override async Task<IActionResult> Main([ServiceBusTrigger(TopicName, IdentitySubscriptionName, Connection = "ServiceBusConnection")] string request, ExecutionContext executionContext)
    {
        return await base.Main(request, executionContext);
    }

base.Main also returns an IActionResult.

Our local.settings.json looks like this (just a piece of the file):

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "ServiceBusConnection": "UseDevelopmentStorage=true",

    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
}

The "problem" is that our Function project is not using a regular HostBuilder, it's abstracting with a lot of interfaces. So, for example, I created a new Function project as a test and I could create this:

Program.cs

using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .Build();

host.Run();

We don't have a Program.cs in our solution, just a Startup with a bunch Configure. Maybe I would need to re-create the Function solution, but for now that's not an option.

So, that's why I'm trying to figure out this without having to create a new solution and start from scratch.

Thanks!