Bug 8404 - Directory.GetCurrentDirectory() is always "/"
Summary: Directory.GetCurrentDirectory() is always "/"
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2012-11-14 14:32 UTC by Chris Hamons
Modified: 2014-01-14 16:31 UTC (History)
3 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chris Hamons 2012-11-14 14:32:49 UTC
It appears that Directory.GetCurrentDirectory() is always "/" for MonoMac applications. This means handling relative arguments from command line very difficult.
Comment 1 Mikayla Hutchinson [MSFT] 2012-11-14 16:14:25 UTC
I would guess that's the actual working directory that launch services starts the app with.

How are you passing the commandline args to the app?
Comment 2 Chris Hamons 2012-11-14 16:17:12 UTC
MyApp.app/Contents/MacOS/MyApp.AutomatedTest -c=Param1 -t=Param2

Is there a better way to launch the app? "open MyApp.app" doesn't redirect stdout to the terminal.
Comment 3 Mikayla Hutchinson [MSFT] 2012-11-14 18:41:47 UTC
Hm, if you're opening the app by invoking its executable directly then I would expect the working directory to be your current location unless AppKit is changing it during NSApplication.Init() maybe?

Nope, you won't get stdout if you use open. OTOH, if you run the exe directly, a few things won't behave exactly like they do when opened with launch services, so you may want to add logging to your app.

When running Monomac apps from MD, we run them with Launch Services, but set a special MONOMAC_LOGDIR environment variable that causes the MonoMac entry point to redirect stderr/stdout to log files before hitting Main.
Comment 4 Chris Hamons 2014-01-14 16:31:56 UTC
getcwd() and Directory.GetCurrentDirectory() both agree. This is just how the mac launcher works. :(