-2

I have recently started C# programming, after having a crack at making my own calculator using Windows Forms i have started getting this error message :-

Error 1 Could not write to output file ' c:\filepath\obj\Debug\My Calculator.exe' -- 'The process cannot access the file because it is being used by another process.

  • I have tried turning off my anti-virus
  • It isn't already running

Im not very experienced so i don't know how to write my own code to bypass this error and can find anything useful information on the internet.

Step by step help tips are always welcome :)

edit: i thought it was too obvious too write down but the program i am creating isnt running (even in Task Manager) and im am using VS 2012.

Major
  • 17
  • 1
  • 2
  • 1
    Open up task manager and look for that process, it's probably running. And I just noticed you're trying to write to an `exe` file ? – Omri Aharon Jan 12 '15 at 15:07
  • Look at: http://stackoverflow.com/questions/12301625/visual-studio-could-not-write-to-output-file-obj-debug-foo-bar-dll?rq=1 – Steve Jan 12 '15 at 15:07
  • something is placing a lock on it. if I were you I would restart visual studio but also delete the items in the bin folder. when starting VS - be sure to run it in administrative mode – Ahmed ilyas Jan 12 '15 at 15:07
  • 2
    `The process cannot access the file because it is being used by another process. ` I'd say it's pretty self-explanatory, isn't it? – walther Jan 12 '15 at 15:07
  • make sure your application does not show in the windows task manager. If id does, it is running. Kill the process before you build. This is often the case when you don't stop all threads. – helb Jan 12 '15 at 15:08
  • please tell us what you have tried so far to debug the error – fjuan Jan 12 '15 at 15:09
  • Are you sure that the locked file is the one in the `obj` folder and not the one in the `bin` folder? And what version of Visual Studio are you using? – Steve Jan 12 '15 at 15:15
  • This is probably because you went to c:\filepath\ **obj** \Debug folder and started your application. Make sure you closed your calculator before building in Visual Studio. – Renatas M. Jan 12 '15 at 15:19
  • Have you tried turning it off and on again ? (the computer) – Cosmin Vană Jan 12 '15 at 15:45
  • http://stackoverflow.com/questions/2002273/visual-studio-locks-output-file-on-build and also this one http://stackoverflow.com/questions/11646047/error-cannot-access-file-bin-debug-because-it-is-being-used-by-another-proc – Steve Jan 12 '15 at 17:07

2 Answers2

3

This problem usually happens when you try to start the program but haven't closed it after you started it last time.

Things to try:

  1. Close your program (the forms you developed)
  2. Restart Visual Studio
  3. If nothing works, open task manager and look if your program is still running even if you can't see it on the screen.

You can find out which process is using a file by using this tool from Microsoft: http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

Cosmin Vană
  • 1,562
  • 12
  • 28
1

Further to Cosmin's answer, you may have the file in your clipboard, try copying another unrelated file to ensure that the exe is not in your clipboard.

Timmy Fuller
  • 75
  • 1
  • 10