azure-functions-dotnet-worker - Bindings does not pass value tuple input parameters

adriana_malea 141 Reputation points
2024-01-10T15:29:53.36+00:00

Hello,

Following the official page here, it seems that binding value tuple input parameters does not work when using .net 7 with v4 Azure Functions and the following libs:

<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />

<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.0.4" />

<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" />

<PackageReference Include="Microsoft.DurableTask.Client" Version="1.0.5" />

<PackageReference Include="Microsoft.DurableTask.Worker" Version="1.0.5" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />

<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />

Could you please investigate this, because I have run exactly the code from the documentation and the values received in the activity function are NULL. Is this not supported anymore? In the documentation it seems that it should be supported.

doc Binding multiple params

Binding multiple params

Thank you!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,073 questions
0 comments No comments
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,336 Reputation points
    2024-01-10T20:16:54.1866667+00:00

    adriana_malea Thanks for posting your question in Microsoft Q&A. I was able to reproduce this error at my end and see the below findings. Isolated model uses System.Text.Json for serialization and as per discussion: https://github.com/dotnet/runtime/issues/70352 ValueTuples are not serialized by default unless you change options.IncludeFields = true.

    So, I added this configuration in Program.cs like below:

    services.Configure<JsonSerializerOptions>(o => o.IncludeFields = true);
    

    and tested the below code which worked as expected.

            public record CourseInfo(string Major, int UniversityYear);
    
            [Function("GetCourseRecommendations")]
            public static async Task<object> RunOrchestrator(
                [OrchestrationTrigger] TaskOrchestrationContext context)
            {           
                CourseInfo courseRecommendations = await context.CallActivityAsync<CourseInfo>(
                    "CourseRecommendations", ("ComputerScience", 2009));
                return courseRecommendations;
            }
    
            [Function("CourseRecommendations")]
            public static async Task<CourseInfo> Mapper(
                [ActivityTrigger] (string Major, int UniversityYear) studentInfo, FunctionContext executionContext)
            {
                CourseInfo courseInfo = new (studentInfo.Major, studentInfo.UniversityYear);
                return courseInfo;   
            }
    

    However, we don't recommend changing the default behavior as this is considered a risky behavior as described in the repo. So, consider using record instead of ValueTuplelike below:

    public record CourseInfo(string Major, int UniversityYear);
    
            [Function("GetCourseRecommendations")]
            public static async Task<object> RunOrchestrator(
                [OrchestrationTrigger] TaskOrchestrationContext context)
            {           
                CourseInfo courseInfo = new ("ComputerScience", 2009);
                CourseInfo courseRecommendations = await context.CallActivityAsync<CourseInfo>(
                    "CourseRecommendations", courseInfo);
                return courseRecommendations;
            }
    
            [Function("CourseRecommendations")]
            public static async Task<CourseInfo> Mapper(
                [ActivityTrigger] CourseInfo studentInfo, FunctionContext executionContext)
            {
                CourseInfo courseInfo = new (studentInfo.Major, studentInfo.UniversityYear);
                return courseInfo;   
            }
    

    We are working on updating the doc with these details and publish soon. Sorry for the inconvenience caused by this.

    I hope this helps and let us know if any questions.


    If you found the answer to your question helpful, please take a moment to mark it as Yes for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.