Programming for windows: C# DriveInfo class causes windows error popup on newest questions tagged windows – Stack Overflow

When using the DriveInfo class occasionally displays a windows message popup:

There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR1

The code that I am working with is fairly standard:

var driveInfos = DriveInfo.GetDrives();
foreach (DriveInfo driveInfo in driveInfos)
{
    if (driveInfo.IsReady &&
        (driveInfo.DriveType == DriveType.Network || driveInfo.DriveType == DriveType.Removable))
        try
        {
            var driveText = string.Format("{0} ({1})", driveInfo.VolumeLabel, driveInfo.Name);

Having had a look on the web it turns out that this is an uncommon error but one that seems be due to environmental issues on the machine (people report it happening when running things like chrome). A lot of people have fixed this by cleaning up old usb references.

The error doesn’t actually stop the program from working normally apart from displaying the message. ( And doesn’t get trapped in the catch block )

As its a wpf application that is a going to be distributed and run on end users pc’s I rather that the message box is not displayed. How can I do this and what are the implications?

See Answers


source: http://stackoverflow.com/questions/11444375/c-sharp-driveinfo-class-causes-windows-error-popup
Programming for windows: programming-for-windows



online applications demo