Azure / Azure/azure-functions-host

Http trigger serializes returned ValueTask<IActionResult> as POCO

Open
#7,120 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 10h
Merged PRs (30d)
36

Description

Http triggers allow you to return a `Task`, and the host will await the task and execute the result. However, if I return a `ValueTask` instead, the whole value task is serialized:

[FunctionName("Foo")]
public ValueTask ExecuteAsync([HttpTrigger(AuthorizationLevel.Function, "get")]HttpRequest request)
{
return new ValueTask(OkObjectResult("Foo"));
}

Expected output:

"Foo"

Actual output:

{
"isCompleted": false,
"isCompletedSuccessfully": false,
"isFaulted": false,
"isCanceled": false,
"result": {
"value": "Foo",
"formatters": [],
"contentTypes": [],
"declaredType": null,
"statusCode": 200
}
}

In most cases the return type of the function can simply be changed from `ValueTask` to `Task`. However it is not the behaviour I expected, and since there is already a check for `Task`, I imagine it wouldn't be hard to also check for `ValueTask`. I'm happy to implement this if I'm allowed.

- Microsoft.NET.Sdk.Functions 3.0.11

Contributor guide

Open the contributing guide

Research direction

Start at the HTTP trigger return-value handling and locate the existing check for Task results. Reproduce the example with a ValueTask and compare it with the Task behavior. Done means the ValueTask is awaited and its IActionResult is executed so the response is "Foo" rather than serialized ValueTask state.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.