I recently upgraded a .NET Function App from the in-process worker model to the isolated worker model.
After the upgrade, I noticed that none of the HTTP-triggered APIs were returning any data.
On further investigation I found that the return types were declared as ActionResult<T>.
When I changed the return types to IActionResult, the APIs started working again.
Example
I created a simple example app using the isolated model to illustrate the issue.
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
namespace FunctionApp1;
public class Function1
{
[Function("Function1")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
return new OkObjectResult("Hello World"); //Works fine
}
[Function("Function2")]
public ActionResult<string> Run2([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
return "Hello World"; //Returning Nothing
}
[Function("Function4")]
public ActionResult<string> Run4([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
return new OkObjectResult("Hello World"); //This is how the api's were returning data before, Returning nothing after update
}
[Function("Function3")]
public async Task<ActionResult<MyReturnType>> Run3([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
return await Task.FromResult<MyReturnType>(new MyReturnType("Jack", "BlacK")); // Returning Nothing
}
public record MyReturnType(string Name, string Surname);
}
Questions
- Is
ActionResult<T>not supported in the isolated worker model? - Why can the runtime unwrap
ActionResult<T>in the in-process model but not in the isolated worker model? - Am I missing some configuration, or is the only supported pattern to return
HttpResponseData/IActionResult?