Error: Cannot access file bin/Debug/… because it i

2019-01-03 22:39发布

When I debug my project, I get following error:

"Unable to copy file "obj\Debug\My Dream.exe" to "bin\Debug\My Dream.exe". The process cannot access the file 'bin\Debug\My Dream.exe' because it is being used by another process."

Using Process Explorer, I see that MyApplication.exe was out but System process still uses it although I stopped debug before. Whenever I change my code and start debug it is going to happen. If I copy project to USB and debug, it runs OK.

Why? How can I fix this error?

I use Window 7 Professional. With Xp I have never got this error.

26条回答
Lonely孤独者°
2楼-- · 2019-01-03 23:25

I have opened a separate question regarding VS 2017 that had a similar behavior after one update. The problem seemed to be generated by the antivirus program although.

I have added the bin folder to the antivirus exclude list, restarted the machine and now it seems to work.

查看更多
我命由我不由天
3楼-- · 2019-01-03 23:27

At least in my case I've noticed that visual studio 2012 was creating at least two msbuild.exe ghost processes, which did not perish after build. These zombies apparently are causing file locks to appear.

Killing msbuild.exe's is one time solution, it needs to be done per build basis.

But then I've figure out that I could disable parallel build once and for all - went into Tools > Options > Projects and Solutions > Build and Run > "maximum numbers of parallel project builds" - by default it has value of 8, I've switched to 1. Works like charm.

Of course builds are bit slower now, but better safe than sorry. At least for this particular small project I did not need more than one build thread.

查看更多
登录 后发表回答