Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting this error again and again. Every time I make changes in my app and when I debug my application second time this error comes in. Only to get rid from this error is to logoff the pc then login again.

Can anyone tell me why is this error coming again and again, and how to get rid of this.

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

Updated 3-Oct-18 20:05pm

This should not be the case. Normally, if you recompile your application, the process running under debugger is automatically terminated, so it should not cause any trouble.

What you see means only one thing: you have a bug, and a pretty subtle one. Somehow, automatic termination of your application does not stop something else. This happens, but very rarely and usually related to third-party executable module you load (most likely, unmanaged), something which you don't build in your solution. Do you have something like that? I don't have enough information to say more; but you have a general idea.

Share this answer
codegeekalpha 2-Mar-11 15:31pm    
i made a atm simulator.. in which i have a lost of forms.
i thin i am pointing new forms frm the main formm.. and there is the problem..maybe some form remain open.. and that causes it
Sergey Alexandrovich Kryukov 2-Mar-11 20:15pm    
You see, you're not sharing your code or any sound ideas on what can be unusual. More than that, you mentioned having to kill a process but did not share any information on what are you killing. You do not provide enough food for thought. All I know is such things happen, quite rarely and some subtle problem can be a reason.
I have occasionally had the same problem and I have found a way to avoid having to reboot that works most of the time. It is a bit drastic though and as has already been said, is probably caused by a subtle bug, which you should try to resolve.

***** WARNING *****

1. close all other applications except VS.
2. Start Task Manager.
3. On the 'Applications' tab see if your application is there and if so, select it then click the 'End Task' button.
4. Switch to the 'Processes' tab. Look for all instances of yourappname.vshost.exe, select them and click 'End Process'. There may be more than one, so check the whole list.

This saves me from having to reboot 99/100 times on Win XP. I have no idea if it works on other OSs.
Share this answer
ThrishikRam 3-Dec-15 4:13am    
this solution Worked for me with windows 7 OS.. Thanks a lot

Member 13793890 23-Oct-18 2:36am    
Great Answer
Are you trying to overwrite the EXE for a program that is running? Because it is read locked while it executes, which means no delete, no rename, no write.
Share this answer
codegeekalpha 2-Mar-11 7:18am    
it comes in case if applcation is running... but i tried to close all my applcation form to check it again.. but no avail getting same error on debbugging again second time...
tell me the way how to get rid of this..
OriginalGriff 2-Mar-11 7:27am    
Trying to close all the forms in your application does not end your app: if your code is after all the forms are closed then you app is still running until it reaches teh end of teh Main method. Until then, your EXE file is untouchable.

In essence: you can't do it.
Why are you trying to overwrite your own EXE anyway?
Sergey Alexandrovich Kryukov 2-Mar-11 13:22pm    
By the reason I explain in my Answer, it should not normally happen. This is certainly a bug, but may be in 3rd-party code.

It seems that the time you are trying to copy the executable, you are still using it("banksys.exe" from "\bin\Debug\" folder) and therefore system can not replace the same banksys.exe.

Before you are doing the action which tries to replace the exectable, you must close the exectable to avoid this error.

NB: In case youe executable does not have an UI therefore you might not be able close the executable,you can verify this at least by opening task manager, then at the time of error, should get the entry of "banksys.exe". Now if you right click on the process named "banksys.exe" and select "End Process Tree", should be able to continue without error.

Hope that helps,
Share this answer
codegeekalpha 2-Mar-11 7:27am    
it means every time i hve to go to task manager to end task it from the processes.. iss dere any other way to do this..
Sergey Alexandrovich Kryukov 2-Mar-11 13:24pm    
No, you should fix some bug, I'm pretty sure. All should be terminated automatically.

Arindam, you see, you Anwer does not provide full explanation.

From Menu go to Build, Configuration Manager, change the Active Solution Configuration to Release if currently Debug or vice versa, and then should build. Can then go back in ans reset to preferred option.
Share this answer
Member 10266978 1-Apr-14 9:24am    
Great.. Dear, it work.
Member 10266978 1-Apr-14 9:25am    
Nice one

M.R SAMEER BAIG 19-Apr-15 23:45pm    
Thanks Dude Its Worked At Once.
But After Rebuilding The Project.Exe The Same Error Arises During Debug...

Member 11804257 6-Jun-17 21:51pm    
it worked . thanks!
Close the application and delete Obj and bin folder

hope its helped
Share this answer
CHill60 4-Oct-18 4:28am    
Won't work if appname.vshost.exe is still in memory, which can happen even if VS is closed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900