Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new DriveInfo(Path.GetTempPath()) crashes on macOS #12157

Closed
EgorBo opened this issue Dec 20, 2018 · 0 comments
Assignees

Comments

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 20, 2018

string path = Path.GetTempPath();
var driveInfo = new DriveInfo(path);

Crashes with

Unhandled Exception:
System.ArgumentException: The drive name does not exist
Parameter name: driveName
  at System.IO.DriveInfo..ctor (System.String driveName) [0x000b7] in /Users/builder/jenkins/workspace/build-package-osx-mono/master@2/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/DriveInfo.cs:66 
  at defefef.MainClass.Main (System.String[] args) [0x00007] in /Users/egorb/Projects/kkook/defefef/Program.cs:11 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: The drive name does not exist
Parameter name: driveName
  at System.IO.DriveInfo..ctor (System.String driveName) [0x000b7] in /Users/builder/jenkins/workspace/build-package-osx-mono/master@2/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/DriveInfo.cs:66 
  at defefef.MainClass.Main (System.String[] args) [0x00007] in /Users/egorb/Projects/kkook/defefef/Program.cs:11 

But doesn't crash on .NET Core.
.NET Core uses this snippet in order to obtain DriveInfo.DriveFormat property in System.IO tests

On which platforms did you notice this

[x] macOS
[ ] Linux
[ ] Windows

Version Used:

mono-master, macOS

marek-safar added a commit that referenced this issue Feb 21, 2019
…13105)

It's possible to pass any string as an argument to DriveInfo ctor (e.g.  `new DriveInfo(Path.GetTempPath())`). Mono throws ArgumentException if there is no exactly the same drive name in the list of available drives.

I tried to handle this case by extracting any valid drive name from the array of available drives sorted by path in descending order.

Fixes #12157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.