Question:
I recently migrated my Azure Function App from .NET 6 to .NET 8, and initially, everything was working smoothly. However, after some time, I started encountering multiple HTTP 404 errors, which impacted over 1,000 requests within a 24-hour period.
ErrorMessage
Details of My Problem:
-
Migration Context: The migration from .NET 6 to .NET 8 was completed, and all functions were executing correctly right after the transition.
-
Issue Occurrence: After some time, I began receiving 404 Not Found errors for various endpoints that were functioning properly prior to migration.
-
Impact: These errors caused downtime and a poor user experience, affecting over 1,000 requests in 24 hours.
-
Logs Analysis: I reviewed both API Management and function logs but couldn’t identify the root cause.
What I Tried:
-
Verified the migration process and ensured application settings were correct.
-
Reviewed API Management and function logs for discrepancies.
-
Checked routing configurations to make sure they aligned with .NET 8’s setup.
Problem:
I expected the migration to .NET 8 to improve the performance and reliability of my Azure Function App. Instead, I encountered a spike in HTTP 404 errors that were not present in .NET 6.
Here’s a simplified code snippet of one of my Azure Functions:
[Function("MyFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "myendpoint/{id}")] HttpRequest req,
ILogger log,
string id)
{
log.LogInformation("Processing request for ID: " + id);
if (string.IsNullOrEmpty(id))
{
return new BadRequestObjectResult("ID is required.");
}
// Simulate processing the request
var result = await SomeService.ProcessAsync(id);
if (result == null)
{
return new NotFoundResult(); // This is where the 404 error occurs
}
return new OkObjectResult(result);
}
host.json:
{
"version": "2.0",
"functionTimeout": "00:10:00"
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
Logs:
Here’s an example of the 404 error logged:
HttpRequest failed with status code 404 for /myendpoint/1234
Expected Behavior:
When calling the function with a valid id
, I expect it to return a 200 OK response with the processed result. However, after migration, many valid requests are resulting in 404 errors.
2
Answers
The Root Cause Eventually, we identified that the root cause of the 404 errors was the unintentional downgrade of the runtime environment back to .NET 4.0. The switch from .NET 8 to an older version led to the Azure Function App failing to serve the correct resources, which caused the frontend to throw 404 errors.
The Fix To resolve this, we changed the runtime environment back to .NET 8 (Isolated Version). After updating the version in Azure App Service, the Azure Function App returned to normal, and all endpoints worked as expected without any further issues.
Lessons Learned Monitor Platform Settings Post-Migration: Even if everything seems fine after migrating to a newer framework, it’s essential to keep an eye on runtime settings in the hosting environment, such as Azure App Service, to ensure they do not revert to older versions. Log Analysis is Key: When dealing with platform-related issues like these, thorough log analysis of APIM and Azure Function logs can provide invaluable insight into what is happening behind the scenes. Framework Compatibility: Always ensure that the correct framework version is specified and maintained throughout the application's lifecycle to avoid runtime errors.
For more details: https://shorturl.at/OZqDi
[edit – you have now changed your sample code, so this answer won’t correlate. I’m leaving it here because it’s still relevant to people who are migrating from .NET 6]
Migrating from .NET 6 in-process to .NET 8 isolated requires more than just changing the target .NET and Functions runtime version. There are code changes needed too, which it looks like you haven’t done.
For example, your sample code above
hashad this:But in .NET 8 isolated, the attribute would be different:
This would explain why you’re getting 404. Likely you don’t have any working Functions defined, because the attributes are wrong. There may be other problems too, such as how you initialise the application.
A good place to start looking at the requirements for .NET 8 isolated is here: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows#aspnet-core-integration