Thursday, November 6, 2008

Unable to write to output file, your obj\blah.pdb is in use

Update: Ok, so this doesn't work 100% of the time for me now. This problem has gotten on my last nerve, so I just added the following line to the Post-Build sequence to get rid of it forever.

if exist "$(ProjectDir)obj\$(ConfigurationName)\*.pdb" del /F /Q "$(ProjectDir)obj\$(ConfigurationName)\*.pdb"

You'll get a message like.

Ok, this issue really got to me. Somehow one of our solutions was referencing a pdb file inside of the obj directory in an entirely separate solution. I actually verified it was being loaded and used, but forcing a close of the lock had 0 impact on the app in running and debugging.

It seems to affect all versions of Visual Studio from 2003 to 2008. We are running 2008.

I stumbled across a fix for a similar situation here. Basically you can force a move of a special .locked file and all is well.

In short, on your Pre-Build events add
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"