Upgrade Azure Function App from .NET Core 3.1 to .NET8 Isolated Worker Model

It’s been since 2022 when I updated the Azure Function App and it was built with .NET Core 3.1 and running on v3 Azure Function Runtime. There was no concept of isolated model at that time, everything (host and the function code) was running in a single process (in-process). As I attempted to add a new function, I realized big alert on Azure Portal saying current version of app will no longer be supported by Microsoft! Well, I didn’t have a choice but to upgrade to latest version, and opt for isolated model. Why taking the shortcut when support for in-process model will end soon! Made source code of Azure Function App publicly available in GitHub (link at the end of this post).

Microsoft always try to keep the documentation up to date. Only problem is to find the right post! Migrate apps from Azure Functions version 3.x to version 4.x came to the rescue. In the past, I was using Visual Studio Enterprise IDE that makes developers life easy but it is costly. I switched to Visual Studio Code which is free. It’s little bit of struggle initially to get everything setup locally but VS Code will guide you to Extensions you need to run and debug locally!

Azure Portal: Azure Function App

First thing first, I cloned the repo from Azure DevOps so I can start from where I left in 2022! It is extremely important to preserve the source code in a version control repository. Installed the necessary extensions and tools to run Azure Functions locally. Here are some of the extensions that I needed-

Azure Function App Project in VS Code with extensions

Followed the migration guide to update the project file including Azure Functions Version to v4 and Target Framework to net8.0. Added and removed the packages to align with the target framework and runtime version.

Azure Function Project with necessary packages after the upgrade

Ready to Run and Debug? Well, VS Code will help you configure the launch configurations-

Launch configuration for running and debugging locally

Hit Run and Debug, and if there are no errors, you will get to see function urls in terminal window.

Running/Debugging Azure Function in VS Code locally
Debugging Azure Functions in VS Code locally

Okay, all functions are tested locally (used postman) and we are ready to deploy in Azure! I did configure the pipeline to build and deploy. Well, build and deploy succeeded but Azure Function does not work after the deployment!

Azure Pipeline- build and deploy

If you were starting a brand new Azure Function, it will likely be working fine but my case is different. My existing Azure Function App settings and the newly deployed code are out of sync. Updated the settings below in Azure Portal and restarted the app.

Update in Environment Variables/App Settings:
FUNCTIONS_EXTENSION_VERSION = ~4

Update/view in Configuration/Function runtime settings:
Runtime version should says ~4

Update/view in Configuration/General settings:
Stack = .NET
.NET Version = .NET 8 isolated
Platform = 64 Bit

Azure Function App Overview in Azure Portal

Ready to try a simple functions? Click here- https://function.aspnet4you.com/api/getclientipv2

Azure Function .NET8 Isolated model removed the x-forwarded-for header! No big deal, you can inject Middleware at the Host Builder to get it back.

Inject Middleware at the startup

You can find the complete source code of this project at https://github.com/aspnet4you/AzureFunctionAppNET8

Comments are disabled at the blogs to avoid spams. If you have any feedbacks or comments, you are welcome to contact me over LinkedIn.

Leave a Reply