Working on an OOB app.
dynamic fileSystem = AutomationFactory.CreateObject("Scripting.FileSystemObject");
dynamic drives = fileSystem.Drives;
foreach (var drive in drives)
{
DriveCollection.Add(new Drive{
VolumeName = drive.VolumeName,
DriveLetter = drive.DriveLetter,
TotalSpace = drive.TotalSize,
FreeSpace = drive.FreeSpace
});
listBox.Items.Add(string.Format("{0} {1}", drive.DriveLetter, drive.VolumeName));
}
When run in the debugger, 'C' drive is enumerated, then an exception is thrown:
"Exception from HRESULT: 0x800A0047"
When I run the app from the desktop, no drives are enumerated before the exception is thrown.
Any hints on how to protect against this exception? Somehow checking the validity of the 'drive' object before referencing it in the Drive constructor?