This was due to a bug in Visual Studio 2022. I uninstalled the MAUI workload as well as whole Visual Studio 2022, and then reinstalled both again. The error was gone in Visual Studio 2022 v17.12.4.