Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MacCatalyst] OperatingSystem is currently not working #108694

Closed
rolfbjarne opened this issue Oct 9, 2024 · 9 comments · Fixed by #108748 or #109332
Closed

[MacCatalyst] OperatingSystem is currently not working #108694

rolfbjarne opened this issue Oct 9, 2024 · 9 comments · Fixed by #108748 or #109332
Assignees
Labels
area-System.Runtime in-pr There is an active PR which will close this issue when it is merged os-maccatalyst MacCatalyst OS
Milestone

Comments

@rolfbjarne
Copy link
Member

From @PureWeen on Tue, 08 Oct 2024 20:22:20 GMT

Description

It looks like on MacCatalyst the Build on the Environment.OSVersion.Version is set to "-1" so when you call

if (OperatingSystem.IsMacCatalystVersionAtLeast(18,0))

it resolves to false.
This works fine on iOS just not MacCatalyst

Reproduction

aoperatingsystem.zip

Just run the app and I've set a label on the screen to output the value of OSVersion.Version. I've also included some if statements in the main page you can break point

Catalyst

image

iOS

image

Copied from original issue xamarin/xamarin-macios#21390

@rolfbjarne
Copy link
Member Author

From @drasticactions on Wed, 09 Oct 2024 05:31:59 GMT

TL;DR macOS reports 18.0, SDK parses it as a Version which is where the -1 comes from, Runtime check will always report it as below.

https://github.com/drasticactions/MauiRepoRedux/tree/MacCatalystVersion

/// Check for the iOS/MacCatalyst version (returned by 'libobjc.get_operatingSystemVersion') with a >= version comparison. Used to guard APIs that were added in the given iOS release.

スクリーンショット 2024-10-09 14 19 32

[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_iOSSupportVersion", StringMarshalling = StringMarshalling.Utf8)]

Version current = Environment.OSVersion.Version;
if (current.Major != major)
{
return current.Major > major;
}
if (current.Minor != minor)
{
return current.Minor > minor;
}
if (current.Build != build)
{
return current.Build > build;
}

https://github.com/xamarin/xamarin-macios/blob/0db186c75896a516b409274b45136714230d60ab/src/ObjCRuntime/Runtime.cs#L2688-L2702

image

https://github.com/xamarin/xamarin-macios/blob/0db186c75896a516b409274b45136714230d60ab/tests/common/PlatformInfo.cs#L82

That value is coming from SystemVersion.plist, which is 18.0, hence why it would get -1, since it's Version.Parseed and it doesn't have the Build number that it may have had in the past.

|| (current.Revision == -1 && revision == 0); // it is unavailable on OSX and Environment.OSVersion.Version.Revision returns -1

It may be that this needed that the -1 check needs to also be added to build for the same reason as revision, since it can't be assumed that build will be there. Or the SDK code above that fetches the version should always include the build even if the system doesn't provide it.

To work around it, checking against18 0 -1 should work

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 9, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Oct 9, 2024
@am11 am11 added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 9, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@am11
Copy link
Member

am11 commented Oct 9, 2024

cc @akoeplinger, perhaps we can simplify the parsing something like this main...am11:runtime:patch-15, i.e. only require major version and make other optional (base on -1 val)?

@akoeplinger
Copy link
Member

akoeplinger commented Oct 9, 2024

@am11 I think we should fix this in Environment.OSVersion.MacCatalyst.cs instead and default the patch/build version to 0. We already do that for iOS/macOS in GetOperatingSystemVersion in Interop.libobjc.cs

That said, I wonder how this ever worked since e.g. I also don't have a three-part version in /System/Library/CoreServices/SystemVersion.plist on my macOS 14.7 machine and from some quick googling it seems to always have been a two-part string?

@akoeplinger akoeplinger added the os-maccatalyst MacCatalyst OS label Oct 9, 2024
Copy link
Contributor

Tagging subscribers to 'os-maccatalyst': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

@akoeplinger
Copy link
Member

@vitek-karas we probably need to backport this.

@am11
Copy link
Member

am11 commented Oct 9, 2024

Yup, whichever solution makes sense. If it's a bit more general, may just cover more platforms. Version.Parse requires two parts (major and minor) at minimum, everything else is optional and result in -1.

@kotlarmilos kotlarmilos self-assigned this Oct 9, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Oct 10, 2024
@jeffhandley jeffhandley added this to the 9.0.0 milestone Oct 20, 2024
@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label Oct 20, 2024
@kotlarmilos
Copy link
Member

The IsOSVersionAtLeast​ fix will be backported to .NET 9 in a servicing release without the breaking change once the release/9.0-staging becomes available.

@akoeplinger
Copy link
Member

This was backported in #109332

@akoeplinger akoeplinger modified the milestones: 9.0.x, 9.0.2 Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime in-pr There is an active PR which will close this issue when it is merged os-maccatalyst MacCatalyst OS
Projects
None yet
5 participants