Thursday, March 03, 2011

Visual C# error - Unable to copy file .. because it is being used by another process

Since I downloaded Visual C# Express 2010 and migrated all my heating control projects to it, each time I build my main client application I get a really annoying error about the exe file being in use:

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

It seems that the solution to this problem is to add a pre-build event that works some unlocking spell on the exe, found the answer here (which curiously says MS fixed it in 2003)