.NET core 3.1 to .NET 6.0 Azure Function Upgrade error

I was recently updating a .NET core 3.1 project to .NET 6.0 when I received the following error.

System.TypeLoadException: 'Could not load type 'System.Environment' from assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'

I had already updated the project properties to point to .NET 6.0

Updated project properties to .NET 6.0

I had also updated all the packages to ensure they were on their latest releases.

The issue was caused by the projects Azures Functions Version not being correctly updated to the latest version that .NET 6.0 requires. It requires v4 whereas .NET 3.1 uses v3

To Update the Project File in Visual Studio 2022 you need select the Edit Project File Option.

Right click the project that needs updating and select Edit Project File

Then update the version within the AzureFunctionVersion tags

Change the version from v3 to v4

Clean the project and rebuild and you should be good to go.