Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
Using IActionResult with Azure Functions in .NET 5?

After migrating my Azure Functions project to .NET 5, it has started wrapping my responses in a weird wrapper class.

For instance, consider the following endpoint:

public record Response(string SomeValue);

[Function("Get")]
public async Task<IActionResult> Get(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "get-something")]
    HttpRequestData request)
{
    return new OkObjectResult(new Response("hello world"));
}

Before, it would return:

{
    "someValue": "hello world"
}

But now, it returns:

{
  "Value": {
    "SomeValue": "hello world"
  },
  "Formatters": [],
  "ContentTypes": [],
  "DeclaredType": null,
  "StatusCode": 200
}

I get that it must be because it just tries to serialize the object result, but I can't find any documentation on how this is supposed to work in .NET 5.

My main function currently looks like this:

public static async Task Main()
{
    var host = new HostBuilder()
        .ConfigureFunctionsWorkerDefaults(x => 
            x.UseDefaultWorkerMiddleware())
        .ConfigureAppConfiguration((_, builder) => builder
            .AddJsonFile("local.settings.json", true)
            .Build())
        .ConfigureServices(ConfigureServices)
        .Build();

    await host.RunAsync();
}

My project is located here, in case someone are interested: https://github.com/sponsorkit/sponsorkit.io

Currently, my .NET 5 work is on a branch called feature/signup-flow.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Using IActionResult with Azure Functions in .NET 5?

You can't return IActionResult with Azure Functions in .NET 5. Or more generally, you can't return IActionResult with Azure Functions using the isolated process model. Quote from the docs:

For HTTP triggers, you must use HttpRequestData and HttpResponseData to access the request and response data. This is because you don't have access to the original HTTP request and response objects when running out-of-process.

Instead of IActionResult, you need to return HttpResponseData. Example code is here.

over 4 years ago · Santiago Trujillo Relatório

0

To return an object from .NET 5 Azure Functions, use the following code:

var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(obj);
return response;
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda