Bug 5512 - System.IO.Directory.EnumerateDirectories fails to list all directories if CWD changes
Summary: System.IO.Directory.EnumerateDirectories fails to list all directories if CWD...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-06-04 16:24 UTC by Elisée Maurer
Modified: 2018-03-13 11:07 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Elisée Maurer 2012-06-04 16:24:28 UTC
Mono's System.IO.Directory.EnumerateDirectories doesn't list all directories in the specified (relative) path if the CWD changes during enumeration.

My guess is that the .NET version of System.IO.Directory.EnumerateDirectories() keeps a handle to the current working directory or maybe resolves the full path when called and Mono's version fails to do so, which makes it unable to keep enumerating directories if the CWD changes during enumeration.

I encountered this bug with the following code under Linux running Mono 2.10.:

  foreach( string strProjectDirectory in Directory.EnumerateDirectories( "Projects" ) )
    // This method call changes the current working directory at some point
    DoSomethingWithProjectFolder( strProjectDirectory );

    // Other project folders never get enumerated
Comment 1 Marek Safar 2012-06-15 10:09:42 UTC
I cannot reproduce the issue, my simple tests works

using System.IO;
using System;

class C
	public static void Main ()
		foreach (var d in Directory.EnumerateDirectories ("/tmp/1", "*", SearchOption.AllDirectories))
			Directory.SetCurrentDirectory ("/tmp");
			Console.WriteLine (d);
Comment 2 Marek Safar 2018-03-13 11:07:33 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!

Note You need to log in before you can comment on or make changes to this bug.