I keep getting this error during the build of my VS2012 C# project
Error 41 Could not copy "obj\Debug\WeinGartner.WeinCad.exe" to
"bin\Debug\WeinGartner.WeinCad.exe".
Exceeded retry count of 10. Failed.
Error 42 Unable to copy file "obj\Debug\WeinGartner.WeinCad.exe" to
"bin\Debug\WeinGartner.WeinCad.exe". The process cannot access the file
'bin\Debug\WeinGartner.WeinCad.exe' because it is being used by another
process.
Now I've figured out that killing the process
Weingartner.WeinCad.vhost.exe
works (sometimes ) but this is getting on my nerves. Any way to stop this happening at all?
My debugger settings are
@Geoff's (https://stackoverflow.com/a/25251766/3739540) answer is good, but it throws error code 1 on recompile.
Here is what worked for me (2>nul 1>nul on the end + exit 0):
I have noticed some answers that solved my problem, BUT, just in case anyone is having the same problem I was.
IF YOU ARE RUNNING A CONSOLE APP: BEFORE YOU DO ANYTHING ELSE.
Make sure you have closed out any console windows that may have been opened from a previous build. For instance I was just testing some code in a console application, I didn't realize that the console window from one of the previous times I ran my program was open. During that session I was debugging, the window got pushed to the back and I couldn't see it. Just saying, this could be your problem, so check to make sure that is not the problem.
For me it was the Avast antivirus that wont let visual studio to write/read/execute file. So I had to add Visual studio 2010/2012 folder to antivirus exclusion list. And right after that baam... it works.
Exception
In some cases in Visual Studio when you (Build || Rebuild) on top of running IISExpress you faced with this Exception:
Solution
You are good 2 GO!
I finally how fix it. Why we can't continue debug after the first debug because the first debug exe still running. So that, after first debug, you need to go to Task Manager -> Process Tab -> [your project name exe] end the exe process.
it works for me :)
the .vhost.exe is a debugger process, so it appears that the process being debugged hasn't closed properly. Chances are you have a bug that's keeping it alive and are not stopping the debug process correctly - there are options to detach from the process when you click 'stop debugging' instead of actually killing the debugger so maybe you have that set.
But that's the problem - the file you're trying to copy over is locked (ie still being used) by the OS so its preventing the copy. Ensure that file is free and you'll be able to copy.