Visual-studio – Unable to copy file reference.dll to bin/reference.dll. The process cannot access the file reference.dll because it is being used by another process

visual studiovisual-studio-2008

For one of my ASP.NET 3.5 applications, every single time I try to build the web app, it throws the following build errors in Visual Studio 2008:

Error 165 Unable to copy file "C:\InOne\Common\DexProcessor\bin\Debug\DexProcessor.dll" to "bin\DexProcessor.dll". The process cannot access the file 'bin\DexProcessor.dll' because it is being used by another process. InVision2
Error 166 Unable to copy file "C:\InOne\Common\DexParser\bin\Debug\InOne.DexParser.dll" to "bin\InOne.DexParser.dll". The process cannot access the file 'bin\InOne.DexParser.dll' because it is being used by another process. InVision2
Error 167 Unable to copy file "C:\InOne\Common\AlertProcessor\bin\Debug\InOne.Invision.AlertProcessing.dll" to "bin\InOne.Invision.AlertProcessing.dll". The process cannot access the file 'bin\InOne.Invision.AlertProcessing.dll' because it is being used by another process. InVision2
Error 168 Unable to copy file "C:\InOne\Common\InVision.BusinessLogic\bin\Debug\InVision.BusinessLogic.dll" to "bin\InVision.BusinessLogic.dll". The process cannot access the file 'bin\InVision.BusinessLogic.dll' because it is being used by another process. InVision2
Error 169 Unable to copy file "C:\InOne\Common\InVision.Common\bin\Debug\InVision.Common.dll" to "bin\InVision.Common.dll". The process cannot access the file 'bin\InVision.Common.dll' because it is being used by another process. InVision2
Error 170 Unable to copy file "C:\InOne\Data\bin\Debug\InVision.Data.dll" to "bin\InVision.Data.dll". The process cannot access the file 'bin\InVision.Data.dll' because it is being used by another process. InVision2
Error 171 Unable to copy file "C:\InOne\Common\InVision.DataAccessLayer\bin\Debug\InVision.DataAccessLayer.dll" to "bin\InVision.DataAccessLayer.dll". The process cannot access the file 'bin\InVision.DataAccessLayer.dll' because it is being used by another process. InVision2
Error 172 Unable to copy file "C:\InOne\Common\InVision.DataAccessLayer.SqlClient\bin\Debug\InVision.DataAccessLayer.SqlClient.dll" to "bin\InVision.DataAccessLayer.SqlClient.dll". The process cannot access the file 'bin\InVision.DataAccessLayer.SqlClient.dll' because it is being used by another process. InVision2

This just started happening a week ago and is very annoying… I have to go into the web app's bin folder and delete the pdb files and then it'll let me delete the dll's most of the time. Every once in a while it doesn't let me so I have to close Visual Studio and then it lets me delete them. I checked and it's Visual Studio (devenv) that is locking the dll's. Rebooting the machine doesn't help.

This is really reducing my productivity, is there anything I can do to resolve this?


As mentioned, Visual Studio 2008 (devenv.exe) is the process locking the DLLs.

I noticed something… When it compiles successfully, it's copying all the DLLs into the bin folder, then they are all deleted, then a new set are copied into the bin. When it isn't successfull, the first set of DLLs are copied in, then it fails. So it seems to be using the bin folder for 2 things when it should only be for 1. Does this help??

Best Answer

The issue ended up being that in the web.config someone had added:

hostingEnvironment shadowCopyBinAssemblies="false"

After commenting this out, everything started building ok. What a nightmare!!