Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.93k stars 440 forks source link

HttpTrigger cannot bind to customobject named "data" #6748

Open mountain65 opened 4 years ago

mountain65 commented 4 years ago

This happens running it locally using the Azure Core Tools. Never tried it on Azure.

Investigative information

Please provide the following:

Repro steps

Provide the steps required to reproduce the problem:

  1. Create a new Azure Function App in Visual Studio 2019 (16.7.5)
  2. Choose HttpBinding
  3. Replace the HttpReqeust with a custom class. See code below
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;

namespace FunctionApp
{
    public class MyFunctionApp
    {
        [FunctionName("MyFunction")]
        public IActionResult Run([HttpTrigger()] CustomObject data)
        {
            return new OkResult();
        }
    }

    public class CustomObject
    {
        public string Data { get; set; }
    }
}
  1. Run it with F5

Expected behavior

A normal run where the Core Tools tell me on what port my application is listening.

Actual behavior

A runtime error:

[2020-10-03T08:46:01.699] Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: Can't bind parameter 'data' to type 'FunctionAPp.CustomObject'. [2020-10-03T08:46:01.748] Error indexing method 'MyFunction' [2020-10-03T08:46:01.750] Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: Can't bind parameter 'data' to type 'FunctionAPp.CustomObject'.

Known workarounds

There are two workarounds:

  1. Name the parameter to the function anything else than "data".
  2. Name the property of the custom object anything else than "Data"

Related information

C#

CSPROJ:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
mountain65 commented 3 years ago

It is not limited to the string/name "data". It also happens when you name your parameter "customer" and you try to bind to an object that has a "customer" property one level below the root.

v-bbalaiagar commented 3 years ago

Hi @mountain65, Apologies for the delayed response, the issue was somehow lost in the trace. I am able to reproduce the mentioned scenario exactly. We will check for the possibilities internally and update you with the findings.