Thursday, September 30, 2010

Quick way to determine processes which use dll assembly

In every day Sharepoint development we often need to update assemblies in GAC via WSPBuilder. Sometimes (especially if you use ReSharper) you will see access denied exception which is caused by the fact that assembly being updated is locked by another process:

   1: WSPBuilder AddIn Error
   2: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   3:    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   4:    at System.GACManagedAccess.AssemblyCache.InstallAssembly(String assemblyPath, InstallReference reference, AssemblyCommitFlags flags)
   5:    at WSPTools.VisualStudio.VSAddIn.Library.Commands.CopyToGAC.Execute()
   6:    at WSPTools.VisualStudio.VSAddIn.VSMenuHandler.Execute(String commandName)
   7:    at WSPTools.VisualStudio.VSAddIn.Connect.Exec(String commandName, vsCommandExecOption executeOption, Object& varIn, Object& varOut, Boolean& handled)

Sometimes adding assembly 2nd time solves the problem, sometimes not. In the last case you need to determine what process blocked your assembly. In order to do it you can use GUI procexp utility (Ctrl+F to find dlls attached to process) from Sysinternals. There is also built-in Windows utility tasklist which allows you to find what processes use specified dll assembly:

   1: tasklist /m myassembly.dll
   2:  
   3: Image Name                     PID Modules
   4: ========================= ======== ============================================
   5: devenv.exe                    2332 myassembly.dll
   6: w3wp.exe                      2892 myassembly.dll

This little tip may help you not only in Sharepoint development as well.

No comments:

Post a Comment