Reputation: 45
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)
Project configuration
Nugets
Project
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;
}
}
Upvotes: 1
Views: 5533
Reputation: 14432
I know you found the answer to your problem, but recently I had the same issue after upgrading to .NET 6 (LTS) and your solution didn't work unfortunately.
What worked for me was changing the return type from Task<HttpResponseMessage>
to Task<IActionResult>
and then change the return from req.CreateResponse(HttpStatusCode.OK, "MESSAGE")
to return new OkObjectResult("MESSAGE")
.
Upvotes: 0
Reputation: 45
I found the error. After migrate .Net core 3.1 to .Net 6 some consideration arise:
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
Upvotes: 0
Reputation: 905
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
{
// your code goes here
return req.CreateResponse(HttpStatusCode.OK, "Done");
Upvotes: 1