Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
I'm not sure if this is even a bug, but it was a small issue for me when I was running mac-samples/MicroSamples/generate-pdf.cs
It's trying to create a PDF with:
> var pdf = new CGContextPDF (NSUrl.FromFilename("demo.pdf"), new RectangleF (0, 0, 617, 792));
demo.pdf somehow resolves to /demo.pdf, which the application doesn't clearly doesn't have permission to write to.Setting to ~/Users/pjbeaman/WorkWork/demo.pdf works just fine.
So then I tried just using Directory.GetCurrentDirectory(), and that seems to be returning a "/".
Should Directory.GetCurrentDirectory() return "/" by default for Xamarin.Mac? The same for a console project spits out "/Users/pjbeaman/Projects/waffwfaw/waffwfaw/bin/Debug" as expected. I don't like to bother with invalid bugs if at all possible, but I asked Jeff and he wasn't sure.
This happens with both 1.4.22 and 1.6.9 Xamarin.Mac, so it's not a regression in X.M at least.
If running as a .app, I would expect this. There is no current directory because the launcher (e.g. 'open') clears parts of the environment environment (notably, PWD).
When running the process directly, the environment is preserved.
The only thing I can think of is a fix in Mono where we return $HOME when $PWD is unset. This is also not strictly a Xamarin.Mac bug.
After some more thought and looking into all the code paths, this really isn't a bug at all. This is expected behavior down to the OS.
Essentially, getcwd returns '/' presumably because the launcher itself (e.g. 'open') called chdir to set it so. That means this is the expected working directory in OS X for .apps that are launched "properly".
So I'm conflicted on what to do: on one hand, '/' is lame, since it's useless so we might as well set it to $HOME. On the other hand, the concept of a current working directory is useless in OS X in the .app context and it just shouldn't be used. So why bother changing the status-quo?
Yeah, closing as FEATURE since this behavior is consistent with the rest of the OS and native apps that run on it. There is nothing in Mono or Xamarin.Mac that messes with these expectations.
Applications running from the launcher (open) shouldn't even expect to have a working directory since they are not launched from one in the first place.
Thanks for the explanation. Makes sense. VERIFYING as FEATURE.