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

Process.Start() should be supported on MacCatalyst #61295

Closed
chucker opened this issue Nov 7, 2021 · 11 comments · Fixed by #61507
Closed

Process.Start() should be supported on MacCatalyst #61295

chucker opened this issue Nov 7, 2021 · 11 comments · Fixed by #61507

Comments

@chucker
Copy link

chucker commented Nov 7, 2021

Description

In MAUI, Mac UI is accomplished through Catalyst (UIKit for macOS) rather than AppKit. As a side-effect, various internals claim to be iOS. For example, OperatingSystem.IsIOS() will return true on a Mac if the app is a Catalyst app.

If you try Process.Start() or Process.Kill(), you get a PlatformNotSupportedException(). I believe this is by mistake, as starting and killing a process should be possible in macOS (but it indeed isn't in iOS).

In short, I believe that line (and the equivalent for Kill()) should read:

if ((OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) || OperatingSystem.IsTvOS())

In addition, the annotation [UnsupportedOSPlatform("ios")] appears to be wrong, as it triggers a "unsupported on maccatalyst" warning.

Reproduction Steps

  1. Create a project targeting net6.0-maccatalyst, e.g. from the MAUI template.
  2. In MacCatalyst-specific code, call:
			var p = System.Diagnostics.Process.Start("/bin/ls");

Expected behavior

No warning should appear, and the process should launch.

Actual behavior

A warning appears, and launching the process throws in StartCore().

Regression?

This is arguably a regression compared to the Xamarin/Mono toolchain, because it targeted Cocoa (AppKit), not Catalyst (UIKit), where this wasn't a problem.

Known Workarounds

No response

Configuration

dotnet --info output:

~> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.2.21505.57
 Commit:    ab39070116

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.0
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-rc.2.21505.57/

Host (useful for support):
  Version: 6.0.0-rc.2.21480.5
  Commit:  6b11d64e7e

.NET SDKs installed:
  5.0.402 [/usr/local/share/dotnet/sdk]
  6.0.100-rc.2.21505.57 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Diagnostics.Process untriaged New issue has not been triaged by the area owner labels Nov 7, 2021
@ghost
Copy link

ghost commented Nov 7, 2021

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

Issue Details

Description

In MAUI, Mac UI is accomplished through Catalyst (UIKit for macOS) rather than AppKit. As a side-effect, various internals claim to be iOS. For example, OperatingSystem.IsIOS() will return true on a Mac if the app is a Catalyst app.

If you try Process.Start() or Process.Kill(), you get a PlatformNotSupportedException(). I believe this is by mistake, as starting and killing a process should be possible in macOS (but it indeed isn't in iOS).

In short, I believe that line (and the equivalent for Kill()) should read:

if ((OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) || OperatingSystem.IsTvOS())

In addition, the annotation [UnsupportedOSPlatform("ios")] appears to be wrong, as it triggers a "unsupported on maccatalyst" warning.

Reproduction Steps

  1. Create a project targeting net6.0-maccatalyst, e.g. from the MAUI template.
  2. In MacCatalyst-specific code, call:
			var p = System.Diagnostics.Process.Start("/bin/ls");

Expected behavior

No warning should appear, and the process should launch.

Actual behavior

A warning appears, and launching the process throws in StartCore().

Regression?

This is arguably a regression compared to the Xamarin/Mono toolchain, because it targeted Cocoa (AppKit), not Catalyst (UIKit), where this wasn't a problem.

Known Workarounds

No response

Configuration

dotnet --info output:

~> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.2.21505.57
 Commit:    ab39070116

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.0
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-rc.2.21505.57/

Host (useful for support):
  Version: 6.0.0-rc.2.21480.5
  Commit:  6b11d64e7e

.NET SDKs installed:
  5.0.402 [/usr/local/share/dotnet/sdk]
  6.0.100-rc.2.21505.57 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other information

No response

Author: chucker
Assignees: -
Labels:

area-System.Diagnostics.Process, untriaged

Milestone: -

@SingleAccretion SingleAccretion added the os-maccatalyst MacCatalyst OS label Nov 7, 2021
@teo-tsirpanis
Copy link
Contributor

I am not familiar with Apple's technologies, but is launching arbitrary processes actually supported by Catalyst itself on Mac compiters? My guess is that since Catalyst looks more like iOS it also has some of its constraints, to be able to run on both tablets and computers. If you want to launch another app (not process) then I guess there is an API for that, but again I am not knowledgable at all.

@chucker
Copy link
Author

chucker commented Nov 7, 2021

I am not familiar with Apple's technologies, but is launching arbitrary processes actually supported by Catalyst itself on Mac compiters?

I copied the bulk of StartCore() (without the OS check) and it forked a process just fine.

My guess is that since Catalyst looks more like iOS it also has some of its constraints, to be able to run on both tablets and computers.

I don't believe it does. You can use App Sandbox, but I don't think anything about Catalyst forces you into it. Now, since the majority of Catalyst apps will be iOS ports, it's safe to assume many of them won't use a feature that wouldn't also work on iOS. However, since the Xamarin/MAUI team (apparently?) chose to use Catalyst as the new UI toolkit for their Mac apps, I do think this is a relevant issue.

@danmoseley
Copy link
Member

@steveisok thoughts? Seems like the fix is easy unless we know of some pitfall.

I wonder whether there are other places where we have OperatingSystem.IsIOS() that block functionality that works fine on Catalyst.

@marek-safar
Copy link
Contributor

Yeah, we marked the process start this way to keep in in sync with other Apple mobile platforms but the restriction could be removed if it makes sense to have it.

@rolfbjarne for more context

@rolfbjarne
Copy link
Member

I am not familiar with Apple's technologies, but is launching arbitrary processes actually supported by Catalyst itself on Mac compiters?

I copied the bulk of StartCore() (without the OS check) and it forked a process just fine.

If it works fine (and there are tests that test that it works so that we find out if Apple restricts it somehow), then I think it makes sense (and it's fine) to enable Process.Start for Mac Catalyst.

@filipnavara
Copy link
Member

There was originally a problem with the ConfigureTerminalForChildProcess System.Native P/Invoke not being available on the mobile platforms (iOS, tvOS, Mac Catalyst) which propagated all the way up to Process.Start not working and throwing exceptions. This was later resolved in #54273. Omitting the API was intentional at one point in time and not just a fallout from OperatingSystem.IsIOS() == true on Mac Catalyst but the reason for it has passed.

@steveisok
Copy link
Member

We can turn the tests on and see what happens. Our motivation for treating this as PNSE was to match iOS/tvOS behavior.

@danmoseley i don't believe there is anything mistakenly platform confused, but we will do a sanity check.

@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Nov 9, 2021
@marek-safar marek-safar added this to the 7.0.0 milestone Nov 9, 2021
@danmoseley
Copy link
Member

@chucker any interest in offering a PR? We should ensure the tests are enabled for Catalyst at the same time.

@steveisok
Copy link
Member

We had some internal discussion and we think this may work when sandbox mode is off. From what I understand, sandbox mode is required should you want to publish your catalyst app to the app store.

What I think we'll try to do in addition to running tests is try to detect when sandbox mode is on and provide a good error message.

@steveisok
Copy link
Member

To validate for MacCatalyst, we'll need to enable the SecCodeCopySigningInformation entitlement and then check for com.apple.security.app-sandbox.

https://developer.apple.com/forums/thread/62939

@steveisok steveisok modified the milestones: 7.0.0, 6.0.x Nov 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jan 7, 2022
steveisok pushed a commit that referenced this issue Jan 11, 2022
This PR adds support for Process.Start() and Process.Kill() for Mac Catalyst. I also added a way to run Mac Catalyst tests in App Sandbox and I resolved the problems with libproc in App Sandbox (the app is unable to obtain a list of running processes).

Closes #61295, closes #61504.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants