Reputation: 552
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.
Upvotes: 15
Views: 87783
Reputation: 6409
Make sure that none of the folders or project files are marked as 'hidden' in Windows.
I set Windows Explorer to show all hidden files & folders when I've been trying to find and remove the .git
directory. Somehow, I managed to set the folder as 'hidden' during the process. As Explorer was set to show hidden files & folders, I didn't realise my mistake until VS failed to build.
Resetting the 'hidden' attribute was enough to fix the error.
Upvotes: 0
Reputation: 965
I had this problem today.
Symptom:
IntermediateOutputPath
entries in all *.csproj
filesbin\Debug
and bin\Release
directories (it sayed administrator rights are needed, but even with admin rights no access was possible)chdsdk
reported no errorsWhen 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:
IntermediateOutputPath
entries from *.csproj
filesThen 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 (-:
Upvotes: 1
Reputation: 1
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.
Upvotes: 0
Reputation: 1210
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.
Upvotes: 0
Reputation: 23
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.
Upvotes: 0
Reputation: 1801
Symantec Endpoint Protection caused this on my pc. It had quarantined the output folder (set it to readonly), believing it was infected.
Upvotes: 0
Reputation: 355
I had the same problem, by running VS2019 as administrator solved the issue.
Upvotes: 0
Reputation: 2039
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
Upvotes: 0
Reputation: 1
I've been experiencing this problem now for the last 9 months, in VS2015 and VS2017 community editions. It appears that the compiler continues to live after the first compile for about 20 minutes, all the while holding locks on the files.
My workaround is to kill the compiler, then rebuild. This always works without any apparent adverse side effects.
You can kill the compiler from the Package Manager Console (or from PowerShell) with this code:
Get-Process | where {$_.ProcessName -eq "VBCSCompiler"} | foreach {Stop-Process -Id $_.Id}
Hope this helps you as it has me for the past couple of months.
Upvotes: -1
Reputation: 2133
An XML file generated by my solution had the Read-only attribute set for a file version generated by another build. After the Read-only attribute was turned off for this file, my build ran without the path is denied error.
Upvotes: 0
Reputation: 540
I recently had this issue. I manually deleted and replaced the file and continued to have the access error. I restarted my laptop and I was able to build and run my project.
Upvotes: 0
Reputation: 11
I added a web service/reference to my Web Server and then my Visual Studio went all crazy and wouldnt recoginze and custom controls or web services. The pages worked for the end users.. Just had access / recognition issues in VS.
I saw a few posts to remove cache files in C:\Users\gklein\AppData\Roaming\Microsoft\VisualStudio\10.0\ReflectedSchemas - I did that but it didnt work for me...
What did work was when i recompiled the web server, there was an error about access to C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\remedy\7642007a\c5be7720\App_WebReference file/folder...
My web server runs impersonating a global network user with elevated access rights...But they recently migrated my pc to a new domain where that user has no rights. The web site couldnt compile (as that user) on my pc. - Once I manually added that global network user as an admin on my pc... cleared cache and restarted VS.. IT WORKED!!!
hope my experience helps some else tooo
Upvotes: 0
Reputation: 101
Have you tried running VS as an administrator? I've run into this problem recently and searched online to see if anyone has found an answer to it. The only thing I do that works is run as an administrator, but I hate having to do that.
[edit] I just read a subsequent comment by someone else about turning on Application Experience in services. That seems to have fixed it for me. I've been running on Windows client for years and just recently switched to Windows Server, which explains why I hadn't run into it before.
Upvotes: 0
Reputation: 119
Have you tried enable windows service 'Application Experience'? This solved my problem after struggling for several days.
http://www.codeproject.com/Questions/296249/Visual-Studio-2010-Access-Denied-Errors
Upvotes: 4
Reputation: 3997
You can Run a program called Unlocker.exe which is a small program which unlocks the locked program.
Try to unlock the exe which is locked and it will give you the exact program which is locking it.
This will help you pin point the problem.
Upvotes: 0
Reputation: 52645
First check to see if you can delete the EXE. If you can't that means some process has a handle on it.
Run Process Explorer and do a search for TestApplication.exe to find what it is
Upvotes: 4
Reputation: 3129
Do you have your bin folder included in your svn? In general, you shouldn't do this, for exacly this reason.
These folders - bin and obj - are generated by VS, and so shoudl be regenerated if you check out the code again.
Upvotes: 2