Bug 44248 - xamarin_get_original_working_directory_path should be promoted to a 'real' API.
Summary: xamarin_get_original_working_directory_path should be promoted to a 'real' API.
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2016-09-13 13:53 UTC by Terry Reese
Modified: 2016-09-13 20:48 UTC (History)
1 user (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 Terry Reese 2016-09-13 13:53:47 UTC
This is a known issue, that we've hit before. The way that our launcher currently works is overwriting the currently launch directory.


If you are willing to depend on some less that documented behavior (though it is likely not changing) then you could do something like:

    [DllImport ("__Internal")]
    public static extern IntPtr xamarin_get_original_working_directory_path ();

    public override void DidFinishLaunching (NSNotification notification)
        string real_path = Marshal.PtrToStringAuto (xamarin_get_original_working_directory_path ());
        Console.WriteLine (real_path);


Chris's suggestion works like a treat, but it would be nice to see this functionality fully supported.  Using this kind of undocumented functionality makes me a little nervous.
Comment 1 Chris Hamons 2016-09-13 20:48:31 UTC
From - https://forums.xamarin.com/discussion/74338/get-the-current-working-directory-for-a-terminal-application#

However, I'm smart. We already have it exposed:

ObjCRuntime.Runtime.OriginalWorkingDirectory. I just missed it.