Bug 5453 - Environment.OSVersion.Platform returns Unix on Mac. Should also return iOS and Android values.
Summary: Environment.OSVersion.Platform returns Unix on Mac. Should also return iOS an...
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.3.x
Hardware: Macintosh All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
: 6153 ()
Depends on:
Blocks:
 
Reported: 2012-06-01 07:54 UTC by Anthony Lambert
Modified: 2012-07-17 15:49 UTC (History)
5 users (show)

Tags:
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:
Status:
RESOLVED NOT_ON_ROADMAP

Description Anthony Lambert 2012-06-01 07:54:41 UTC
I got this code...

BuildOSObj(
                Environment.OSVersion.Platform,
                Environment.OSVersion.Version );

On my Mac when I'm building with Mono (not monotouch) it returns:
Unix 11.4.0.0

When I look in the PlatformID in the object browser the MacOsx platform is defined so is XBox as well as a large number of native Windows IDs....

This isn't working correctly it shouldn't currently return the Platform as UNIX but MacOsx.

Also it would be really great if it was expanded to include iOS and Android.
Comment 1 Sebastien Pouliot 2012-06-01 08:14:23 UTC
The enumeration type (and values) comes from Microsoft. The Mono project added a "special" value (128) to represent Unic back in the .NET 1.x days (when Unix was not defined). It was very helpful at the time.

That turned out, later, to be a mixed blessing since MS added Unix later (value 6) along with other values, e.g. Mac. Backward compatibility requires us to still support 128 (along with 6) which is not a big issue. 

However supporting 'Mac' (which is Unix too) turned out to regress quite a bit of code (including a lot of 3rd party code and common, reusable, libraries). As such it is unlikely that we'll add more of our own values *directly* in this enumeration.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-07-17 06:56:38 UTC
*** Bug 6153 has been marked as a duplicate of this bug. ***
Comment 3 Attila Tamás Zimler 2012-07-17 07:55:56 UTC
Makes sense for not extending what Microsoft is not extending to keep compatibility. And what about extending Mono.Unix.UnixEnvironment?
Comment 4 Jonathan Pryor 2012-07-17 15:30:28 UTC
@Attila: We could certainly add something to UnixEnvironment, though:

1. I'm not sure what you're thinking of adding. Feature checks (e.g. does this file/export exist?) would still be better, even on OS X, because history has shown that platform version checks are brittle and easy to get wrong. Knowing that you're on OS X doesn't necessarily help, as the given functionality you want may require Lion, now Snow Leopard, etc. If you need to check for platform + version, you might as well use feature checks instead.

2. If you really want a platform check, there's always Mono.Unix.Native.Syscall.uname()...

3. Using UnixEnvironment would require referencing Mono.Posix.dll, which is less than ideal in a variety of circumstances. For example, none of Mono's BCL code could use it.
Comment 5 Attila Tamás Zimler 2012-07-17 15:49:34 UTC
I'm thinking to add a correct OSVersion property to the UnixEnvironment which contains those functionalities that makes sense to Mono but maybe not making sense to .NET and are not available on Microsoft's platform. That way we could keep the compatilibility.

For platform version check, I found an article that describes the correct method (http://cocoadev.com/wiki/DeterminingOSVersion), but had no time to check it yet. I agree that if it is extended it should be done correctly and report correct OS versions too. Anyway my problem when I found out that MacOSX was not reported correctly was that I tried to implement a warning for myself that MacOSX's syslog does not support LOG_DEBUG and LOG_NOTICE (see bug 6125). In this case it is completly enough to know that the OS is MacOSX.

I don't know what BCL stands for but if you would like to use any of the Unix specific functionality like directory right management and so on, you should have a reference to Mono.Posix.dll anyway, so if you're doing low level fun I think that could be no problem from the code depending on the framework (or if it is I think the user of the dll should dependency inject it). From the point of the code inside the framework, I don't know if it is a problem or not.