This error happened to me when I was using Visual Studio Code.
I think it must have been because I was trying to build a project while there was an executable running in the same bin\debug folder.
I stopped the executable, closed the folder, reopened, rebuilt, and the error went away.