This was due to a bug in Visual Studio. I uninstalled the MAUI workload as well as whole Visual Studio , and then reinstalled both again. The error was gone in Visual Studio 2022 v17.12.4. You might need to uninstall and reinstall your version of VS again.