[Mono-bugs] [Bug 78209][Nor] New - Directory.GetParent(path) fails for path=file in the current directory (doesn't fail on MS)

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Apr 26 10:13:46 EDT 2006

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by dredconrad at gmail.com.


--- shadow/78209	2006-04-26 10:13:46.000000000 -0400
+++ shadow/78209.tmp.11387	2006-04-26 10:13:46.000000000 -0400
@@ -0,0 +1,82 @@
+Bug#: 78209
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details: 
+Status: NEW   
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: dredconrad at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: Directory.GetParent(path) fails for path=file in the current directory (doesn't fail on MS)
+Description of Problem:
+Directory.GetParent(path) fails for path=file in the current directory
+(doesn't fail on MS). This is because GetParent is implemented with
+Path.GetDirectoryName, which returns "" in such a case and this gets passed
+to new DirectoryInfo(""), which bombs (as it should). The fix is to make a
+special case in GetParent for files in the current directory... see
+attached diff.
+Steps to reproduce the problem, here's a test case:
+using System;
+using System.IO;
+public class Test
+        public static void Main(String[] args)
+        {
+                if(args.Length < 1)
+                        Console.WriteLine("one argument (filename) required");
+                Console.WriteLine("parent directory is " +
+        }
+Actual Results:
+Unhandled Exception: System.ArgumentException: path
+Parameter name: Empty path.
+in <0x0003e> System.IO.FileSystemInfo:CheckPath (System.String path)
+in <0x0001b> System.IO.DirectoryInfo:.ctor (System.String path)
+in (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:.ctor (string)
+in <0x00096> System.IO.Directory:GetParent (System.String path)
+in <0x00034> Test:Main (System.String[] args)
+Expected Results: The current directory name should be returned.
+How often does this happen? Always.
+Here's the diff for mcs/class/corlib/System.IO/Directory.cs:
+Index: mcs/class/corlib/System.IO/Directory.cs
+--- mcs/class/corlib/System.IO/Directory.cs     (revision 59863)
++++ mcs/class/corlib/System.IO/Directory.cs     (working copy)
+@@ -299,7 +299,13 @@
+                        if (IsRootDirectory (path))
+                                return null;
+-                       return new DirectoryInfo (Path.GetDirectoryName
++                       // get directory name for path
++                       string dir = Path.GetDirectoryName(path);
++                       if(dir == String.Empty) // i.e., no directory
+information, file in current directory
++                               return new DirectoryInfo
++                       else
++                               return new DirectoryInfo
+(Path.GetDirectoryName (path));
+                }
+                public static void Move (string src, string dest)

More information about the mono-bugs mailing list