First ensure that the problem is with the Visual studio and not the dotnet sdk by trying other IDEs such as Rider.
If the issue persists remove dotnet folder and reinstall the sdk and try again. In the end you can attempt repairing the visual studio as well.