1
Vote

Directory Not Found exception

description

User Scott MacLellan reported issues with directory not found exceptions in certain cases. He submitted a patch via email:
 
The bug was caused by the "TestResult" directory being deleted and then subsequently trying to retrieve the list of child directories. Since the directory has been deleted this call would throw an exception:
 
Line 55: var subDirectories = Directory.GetDirectories(startDir);
 
If other folders were deleted by the build process this would probably have also caused problems.
 
To prevent this I added checks to make sure the directory exists in the ProcessDirectory method and wrapped the line shown above with a simple try catch.
 
private static void ProcessDirectory(string startDir, List<ManualResetEvent> waitHandles)
{
// If the directory has been removed don't worry about it
if (!Directory.Exists(startDir)) return;
 
// ... the other code goes here.
}
 
I used the tool to clean up a pretty large source tree, ~2GB, and it worked pretty well after I added this fix. It also seemed to work fine for VS2010 projects but that could have just been me getting lucky. In the file I sent you I added another small modification to hide the processes spawned to build each solution.
 
var build = Process.Start(new ProcessStartInfo(MSBuildPath)
{
   Arguments = string.Format("\"{0}\" /m /t:clean", solution),
   WindowStyle = ProcessWindowStyle.Hidden, // (sjm) - prevents new processes from being shown to the user
});

comments