Description
When enumerating drive information using DriveInfo.GetDrives() the returned data may be invalid (incorrect Name, DriveType, and RootDirectory) for mounted optical disc if the volume label has spaces in it.
The exact same code worked in previous versions of .NET.
Reproduction Steps
var drives = System.IO.DriveInfo.GetDrives().ToList();
Console.WriteLine($"Found {drives.Count} drives);
foreach (var drive in drives)
{
Console.WriteLine($"{drive.Name} (type: {drive.DriveType}): {drive.RootDirectory}");
}
run with dotnet run --framework 9.0 ./program.cs vs dotnet run ./program.cs with dotnet-sdk-10.0 installed
Expected behavior
Name and RootDirectory point to the mount point (usually something like /run/media/username/DISC LABEL), and DriveType == CDRom
Actual behavior
Name and RootDirectory are broken (/run/media/username/DISC\0403), and DriveType == NoRootDirectory
Regression?
Yes, the same code worked fine with .NET 8 and 9
Known Workarounds
No response
Configuration
Tested using .NET SDK 9.0.11 and 10.0.1 on Fedora 42, but I got reports from NixOS and Bazzite
Other information
No response