The process cannot access the file because it is being used by another process.

Ever seen the error in the title…the one that happens when you rebuild your project in VS and it says:

Error 1 Could not write to output file Foo.exe’ —‘The process cannot access the file because it is being used by another process. ‘

This is a very frustrating error that many users have complained to us about in VS 2003. We have spent many hours figuring out these problems and fixing them. In Whidbey, we want to fix any bugs like these – we’ve fixed known issues from VS 2003, but if you happen to see one of these in Beta2, here’s a guide of things to do. Please report the following stuff to us in the bug you open at the Product feedback site:

  1. Are any Visual Designers open? Does closing Visual Designers (and restarting devenv) help?
  2. Install Process Explorer from Search for handles open on the output file (Foo.exe/Foo.dll). Who is holding handles on it? 
  3. Is the Object Browser open? Does closing it help? Does closing it and restarting devenv help?
  4. Provide an inventory of all windows (including tool windows) open. Sometimes one of these windows has a component loaded locking the dll.
  5. If you can, please send the solution that repros the problem (if you have a consistent repro).
  6. Are any addins running when this error occurs? Perhaps disabling addins helps?

Hopefully, going through these steps should also help you find a workaround for this annoying issue. Please report it to us if you do see it – we want to fix all of these.



Comments (6)

  1. Actually, closing object browser won’t unload the DLL (if it was indeeded loading into object browser). You need to remove the library from object browser. Once done, you don’t even need to restart VS.

  2. Pablo says:

    I have to close & reopen the solution for the files to get ‘unlocked’ , sometimes the files are locked just by opening the solution, and almost never happens on the final dll (web app), only on dependencies. Also some of the .xml files (documentation) get locked too and that messes with intellisense.

  3. shaykatc says:

    Pablo, does this happen with Beta2?

  4. Pablo says:

    ops.. sorry, that was 2003,

    I’ve only tested beta1 (very little) so far…

  5.;en-us;843370 might help for the VS2003 issues.

    Otherwise search the KB with keyword kbvsnet2003presp1fix looking for fixes.

  6. Wes says:

    Make sure the indexing service is turned off.