Another thing to check is to make absolutely sure that the file(s) you are targeting with your task are contained within the root of your VSCode project folder at or below the same level as your .vscode folder that contains the tasks.json file.
I just experienced the same issue with a C project. Restarting VSCode and rebooting the computer had no effect. I eventually realized the copy of the .c file I was attempting to build had been opened from outside the root of the project. Once I opened the correct file inside the project folder everything worked as expected.