Azure / Azure/azure-functions-host

Serialization issue with V3 when using HttpRequestMessage.CreateResponse(.., JArray)

Open
#7,145 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

This was reported by a customer through a servicing ticket.

Here's a sample function that fails with a "Stack Overflow". This seemed to work fine in V2 function apps. --

```csharp
[FunctionName("HttpTrigger")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
JArray jArray = new JArray();

return req.CreateResponse(HttpStatusCode.OK, jArray);
}
```

The workaround seems to be using `jArray.ToString()` this way, AND allowing synchronous IO by turning the flag `FUNCTIONS_V2_COMPATIBILITY_MODE` to `true`.

```csharp
[FunctionName("HttpTrigger2")]
public static HttpResponseMessage RunMe(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
JArray jArray = new JArray();

return req.CreateResponse(HttpStatusCode.OK, jArray.ToString());
}
```

Contributor guide

Open the contributing guide

Research direction

Run the C# HTTP-trigger sample and begin at req.CreateResponse(HttpStatusCode.OK, jArray), comparing it with the JArray.ToString() workaround and the FUNCTIONS_V2_COMPATIBILITY_MODE setting. Done means returning a JArray response no longer causes a stack overflow in V3 without relying on the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.