Tuesday, August 28, 2012

Cannot Access File 'XXXX' because it is being used by another process - Error on Copying DLL to GAC

This post highlights one of the most common development environment issue you would encounter, when you try to show your tricky deployment steps.

Problem
Most of you all would not depend on the fresh deployment, where there is a possibility to ‘GAC’ the DLL. But in some cases, you would get an error message as follows, when you would try to pull the old DLL out and to put the new DLL in.


Solution
      1.      Get the list of all the processes attached to the interested DLL.
      Use the following command to list all the processes along with the ID.
      Tasklist /m <DLL Name.dll>
      E.g :







     Terminate processes/services shown in that list.
     In my case I had to release the DLL from the SharePoint timer job and the SharePoint worker process. This can be achieved by restarting the SharePoint service and recycling the IIS Pool/resetting the IIS  Server respectively.

     2.   In some cases, having done the above steps would repeatedly showing the same error message as shown      at the start. In such circumstances, you need to consider certain application running in the server. This can be Visual Studio/PowerShell.
Restarting those application would help you to get rid of the above problem.