This is still a problem in VS 2022.
Sometimes nothing helps, error window keeps pop up even when we have zero error.
In that case deleting the ".vs" folder in the solution root folder + restarting may helps.