04 May 2010

How do I – Solve the – Unexpected error creating debug information file .pdb. The process cannot access the file because it is being used by another process. – compiler error?

As a SharePoint Developer, you may run across this error at some point.
image
It is most common when you’re trying to recompile a SharePoint binary, from a Visual Studio session ON the actual SharePoint server.  Of course, in most normal situations, it’s unthinkable to run the compiler on the server, but as SharePoint developers, we know there is no other way to code for the platform so it’s pretty much SOP for us.
The problem lies in the locks that are taken by the compiler process on the debug info file.  Often the locks are taken by your last debug session and unfortunately the locks aren’t always released, even though you’re the same user from the same application.  Call it a multi threading anomaly or something.  Whatever it is, this happens in Visual Studio 2008.
Enter Process Explorer!  This little gem by Mark Russinovich from SysInternals, has been around for a long time, now in it’s 12th version.  Microsoft bought SysInternals a couple of years ago, and with it, Mark’s great mind.  I must say, it was probably one of the smartest acquisitions that Redmond has ever made.  But I digress.  So, if you have Process Explorer installed (if you don’t, download it now and do so), it generally lives in the C:\Program Files\Process Explorer folder.  To unlock your files and resume your compilation, follow these easy steps:
  1. Open Windows Explorer.
  2. Browse to the C:\Program Files\Process Explorer location, or any other alternative location where you may have installed Process Explorer to.
  3. image
  4. Double click “Procexp.exe” to launch Process Explorer.
  5. Once Process Explorer opens, it will display a list of all active processes on your system.  Odds are that your .pdb file is NOT shown here.
  6. In the top menu, click the “Find” menu item.
  7. In the drop down menu, click the “Find Handle or DLL” menu option.  NOTE: If you’re a shortcut kinda guy or gal, you could have accessed this option with the “Ctrl+P” keyboard hotkey combo.
  8. image
  9. In the Process Explorer Search dialog window, enter the name of your DLL, or in our case, the name of our .pdb file.
  10. Click “Search” or press “Enter”.
  11. image
  12. Process Explorer displays the process that has the lock and wouldn’t you know it, it’s Visual Studio itself. 
  13. Double click on the “devenv.exe” line.
  14. Process Explorer now closes the dialog window and the “devenv.exe” item is added to the displayed list.
  15. Right click the “devenv.exe” line in the displayed list.
  16. image
  17. On the popup menu, click the “Close Handle” menu option.
  18. Process Explorer will display a warning message noting stability and crashes that may be caused by closing the handles on this file.  Of course we understand this and we click “Yes”.  Or alternatively, we don’t understand but as a Windows user, we blindly click “Yes” to just make the popup go away. 
  19. image
  20. After closing the handles, we return to Visual Studio and press F5 or click Rebuild and tada!  
  21. image
Happy coding!


Cheers
C

No comments:

Post a Comment

Comments are moderated only for the purpose of keeping pesky spammers at bay.

SharePoint Remote Event Receivers are DEAD!!!

 Well, the time has finally come.  It was evident when Microsoft started pushing everyone to WebHooks, but this FAQ and related announcement...