Search code examples
c#.netazureazure-functions.net-6.0

Azure function .net 6 return error 500 after deploy


I've migrated a project from .net core 3.1 to .net 6.0. I've resolved/updated all nugets and my functions runs well on local environments (I've tested on two pcs). The project has an http trigger and connection to database. When I call the api using postman and it's not necesary in logic connect to database my function return 200 on http status code and expected response body. However, when the function needs connect to database I see on log that the functions get results from database althoug all logic runs well when the function return the response return an error 500.

Any logs regarding to an exception is showed on azure functions logs, I search the data application logs files on kudu as well, but I ddidn't find anything related to the issue

Azure Logs (data in red was retrieved from database) Azure logs

Postman Postman

Project configuration

Nugets

Nugets

Project

enter image description here

Azure Function properties

  • FUNCTIONS_EXTENSION_VERSION: ~4

  • Runtime version: ~4

  • FUNCTIONS_WORKER_RUNTIME: dotnet

Azure Function code

 [FunctionName("FnDealSlip")]
    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/fintech/dealslip")] HttpRequest req,
        ILogger log)
    {

        string offerDate = req.Query["offerDate"];

        try
        {
            return await Invoke(req, log, (request, logger) =>
            {
                return _dealSlipService.GetDealSlipByOfferDate(offerDate);

            },
      (response, httpRequest, logger) =>
      {
          log.LogInformation("Response: " + JsonFormartter.Serialize(response));
          log.LogInformation("Response Status Code: " + JsonFormartter.Serialize(response.StatusCode));
          var actionResponse = new ObjectResult(response)
          {
              StatusCode = response.StatusCode

          };
          log.LogInformation("Response actionResponseSet: true ");
          return actionResponse;
      });
        }
        catch (Exception ex)
        {
            log.LogError("error fn: " + ex.Message);
            throw;
        }
      
    }

Solution

  • I found the error. After migrate .Net core 3.1 to .Net 6 some consideration arise:

    • It's recomended that Azure functions doesn't share an azure account
    • If diferents azure functions share a same storage account its name must be unique

    The error was, the identifier used to link azure function to storage accounts are the first 26 charactes, so, I had differents azure functions sharing a same storing account and its names was longer thant 26 characters, for the link just took first 26 provonking a duplicity on identifiers.

    Solution: Define a custom hostid for each function on azure configuration settings. e.g.

    AzureFunctionsWebHost__hostId=mycustomfunctionname
    

    more details on https://github.com/Azure/azure-functions-host/wiki/Host-IDs#host-id-collisions