简体   繁体   中英

Unable to copy file obj\Debug to bin\Debug Access to the path bin\Debug\ is denied

I created simple wpf application (WpfApp1). I run it and everything was working fine. Then I tried to rebuild the solution and I received an error.

Error: Unable to copy file "obj\\Debug\\WpfApp1.exe" to "bin\\Debug\\WpfApp1.exe". Access to the path 'bin\\Debug\\WpfApp1.exe' is denied.

I restarted VS, cleaned and rebuilt the solution, checked by 'handle' if anything was blocking WpfApp1.exe file (handle "pathToTheFile\\WpfApp1.exe"

result: Nthandle v4.1 - Handle viewer Copyright (C) 1997-2016 Mark Russinovich Sysinternals - www.sysinternals.com

No matching handles found.)

and I checked permission to the folder by right clicking on the folder -> properties -> security (3rd tab). I'm logged under local account with administrator privilages and I'm able to create, rename etc. other files in \\bin folder but I'm not able to do anything with WpfApp1.exe file. I also run VS as an administrator and tried to do the same, but the error apeared.

I work on: win10 home, visual studio 2017 community (15.4.0)

EDIT: repair and reinstallation of VS hasn't helped.

After rebuild proces, .exe file from \\bin is set as deleted, but somehow the file still exists on the disc as a 'ghost' file. In that moment access rights to the file are changed by OS and an owner of that file is unknown (I can't see it because of lack of permission. Before rebuild proces I had full access to the file.) If I restart OS, then the proces of deletion of the file is completed and the file doesn't exist anymore.

I had that error, it was unable to copy it, other times saying it was unable to delete it. (and bear in mind there is the obj\\debug\\blah.exe and the bin\\debug\\blah.exe and the issue can potentially apply to both of them)

I think what happens is visual studio first tries to delete it(them) and if that succeeds(or if it's already deleted), then it tries to copy it.

You can try to delete it yourself and then you see there's some issue with deleting it.. So you can try closing explorer windows, and using eg unlocker and file governor. I think you will find that it's probably not visual studio that is locking it. When I tried closing visual studio I still couldn't delete the file, so I can see that visual studio would have an issue deleting the file!

Supposing you manage to delete it so visual studio would manage it or not need to. So now there's the error about it not being able to copy the file. I see you checked permissions on the directory..that's good And if you find you get an error along the lines of not being unable to write to the directory, it may be a permissions issue , or it may be being low on disk space! Though I see in your case it was an anti-virus locking the file and the program you were using to check handles didn't pick that up. But this answer shows some other causes and approaches that may be helpful to others that have the issue.

Added

Another cause is a known issue with certain anti-malware, such as Malware Bytes see here . You can go to the bottom right tray icons and hover over them to see what they are, see if any anti-malware is running. Try quitting if it is and see if that helps.

And another possible cause that has also been shown to affect visual studio when building a project, is the "Application Experience" service which is in Windows 7/8/10 and should apparently be started. Apparently it is 'stopped' for many people. Windows 2008 R2 - Kernel (System Process PID=4) is locking files and folders

@HansPassant your clue regarding to McAfee was correct. Only there was required to restart OS also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM