SHARE:

From .NET 6 to .NET 8, my migration experience: Using OpenApi on Azure Function on .NET 8 isolated

Introduction

I recently migrated an Azure function based on HttpTriggers. This function was running on .NET 6 in-process, and I migrated it to .NET 8 isolated. The only option available since Microsoft will only support isolated mode and no more in-process for Azure functions. In this post, I will show you the necessary modifications regarding OpenApi and Swagger.

Changes to make

Like all migrations from .NET in-process to .NET isolated, you must first upgrade the Nuget packages. In the in-process mode, all Nuget packages containing the keyword “WebJob” must be replaced by the same package by replacing “WebJob” with “Functions.Worker” as follows:

Microsoft.Azure.WebJobs.{feature} -> Microsoft.Azure.Functions.Worker.{feature}

Therefore the Nuget OpenApi package for Azure functions is transformed from Microsoft.Azure.WebJobs.Extensions.OpenApi to Microsoft.Azure.Functions.Worker.Extensions.OpenApi

The code remains exactly the same as follows:

Don’t forget to activate OpenAPI with the ConfigureOpenApi extension in your Program.cs as follows:

You will notice something weird: The namespace won’t change and will remain “Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes”. It’s normal Microsoft hasn’t changed the namespace and there no more Nuget package named “WebJob”:

Let’s run it

If we run it, you’ll see that it’s working like a charm, you can find in the output console the endpoints generated by the OpenAPI Nuget package:

You can invoke the Swagger URL for example as follows:

As you can see, it works fine, and you don’t have to worry about the “WebJob” namespace.

Enjoy your migration 🙂

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.