error in visual studio, Access to the path is denied

Viewed 75848

I've been having this problem for a while now. I created a brand new winforms c# application in Visual Studio. I can usually launch it in debug mode once without a problem. However, if I close it and launch it again I get an error "Unable to copy file TestApplication.exe to bin\release\TestApplication.exe". Access to the path is denied.

This is driving me crazy. Why is this happening? I noticed that the folders are marked as read only. However, when I try to change it nothing happens. My manager suggested that it could be the fault of some of the extensions that I've installed. I'm using Microsoft's power tools as well as AnkhSVN plug in.

16 Answers

I had this problem today.

Symptom:

  • Build error for nearly all projects in my Visual Studio solution (IntermediateOutputPath errors with paths to temporary files)
  • Auto-inserted IntermediateOutputPath entries in all *.csproj files
  • No access to all bin\Debug and bin\Release directories (it sayed administrator rights are needed, but even with admin rights no access was possible)
  • File system check by chdsdk reported no errors

When removing these entries from the project files (by the undo function of the version control system), they were auto-inserted again after a few seconds. Really strange!

Solution:

  • Windows restart
  • Remove auto-inserted IntermediateOutputPath entries from *.csproj files

Then the problem was solved on my system. I hope this helps other people to avoid waste of time. Just try a restart and before hunting a phantom error. Good luck (-:

Had this problem on Windows 10 and it was coming from Windows Defender Antivirus.

I excluded the folder containing the .exe file and it worked again.

You can do that in Windows Security > Virus & threat protection settings > Exclusions

I had the same problem, by running VS2019 as administrator solved the issue.

Symantec Endpoint Protection caused this on my pc. It had quarantined the output folder (set it to readonly), believing it was infected.

Running Visual Studio as administrator is the only way I can solve this problem. That works on my windows 10 laptop, running visual studio 2019 community (version 16.8.3 ).

Note that even though I have changed the properties settings of the VS app by ticking the box "run as administrator" under the properties -> advanced console, I still have to manually select run-as-administrator every time. VS still will NOT run as administrator automatically.

I have previously tried adjusting the windows 10 read/write permissions for every folder and file within the VS solution - that did NOT fix the problem.

The bin folder in my project was read only. Right clicked the bin folder and under properties unchecked the "Read-only" and chose sub folders in the next popup. This resolved the issue for me.

enter image description here

I've had this problem (access to bin folder when debugging) from time to time and usually it's been sufficient to kill the VS process and start over. Today I encountered something odd: In a new TestApplication I was in need for some random numbers, and happily typed the line Random rnd= new Random(); The problem occurred immediately and the only way to get rid of it was by commenting this line. When uncommenting Random rnd = new Random() problem returned.

Related