I also get this error with UE 5.1.
I solved it by going to Visual Studio Installer → Visual Study Community 2022 → Modify - Individual Components → uncheck IDE Support for Unreal Engine.
I’m not sure if it is the correct solution, but worked for me.