dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.56k stars 4.54k forks source link

Unable to use Process.Start() in Mac Catalyst Universal application in Release configuration #100129

Open Bodkens opened 3 months ago

Bodkens commented 3 months ago

Description

I have Mac Catalyst application that needs run another app with. I do this with Process.Start() It works fine in Debug mode, but when i do dotnet publish it does not work in Universal build of Release config. It return me this error below. I turned off sandbox mode. Is there another way and more correct way to start applications in Mac?

Снимок экрана 2024-03-22 в 01 06 18

My workload

Installed Workload Id Manifest Version Installation Source maui-maccatalyst 8.0.7/8.0.100 SDK 8.0.100
maui-ios 8.0.7/8.0.100 SDK 8.0.100
maui-android 8.0.7/8.0.100 SDK 8.0.100
maui 8.0.7/8.0.100 SDK 8.0.100

Steps to Reproduce

1) Create example MAUI App 2) In Platform/Entitlements.plist set com.apple.security.app-sandbox to false 3) Edit MAUI example app to start another app, for example Weather(Weather can crush if we start it that way but main point that it detects and runs weather app)

public partial class MainPage : ContentPage
{
    int count = 0;

    public MainPage()
    {
        InitializeComponent();
    }

    private void OnCounterClicked(object sender, EventArgs e)
    {
        count++;
        try{
            Process.Start("/System/Applications/Weather.app/Contents/MacOS/Weather");
        }
        catch(Exception ex){
            this.DisplayAlert("Error", ex.Message, "Ok"); 
        }

4) Run and see that it works in debug 5) Create release configuration by dotnet publish -f net8.0-maccatalyst -c Release -p:CreatePackage=false 6) Run bin/Release/net8.0-maccatalyst/MauiApp.app and see that it returns Attempting to JIT compile method 'void System.Runtime.Serialization.SerializationGuard:g__ThrowIfDeserializationInProgress|0_0 (System.Runtime.Serialization.SerializationInfo,string,int&)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

Link to public reproduction project repository

No response

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

drasticactions commented 3 months ago

First, this is unrelated to the MAUI UI Framework; this involves the SDK and the runtime. If you reenable the Mono Interpreter (Edit your csproj, add <UseInterpreter>true</UseInterpreter>) then it should allow that to start, but I'm not sure if Process.Start is meant to work in an AOT usecase. @rolfbjarne what do you think?

Bodkens commented 3 months ago

@drasticactions it crashes in case of <UseInterpreter>true</UseInterpreter> in Universal Release configuration

rolfbjarne commented 3 months ago

I can reproduce, this is the stack trace:

System.ExecutionEngineException: Attempting to JIT compile method 'void System.Runtime.Serialization.SerializationGuard:<ThrowIfDeserializationInProgress>g__ThrowIfDeserializationInProgress|0_0 (System.Runtime.Serialization.SerializationInfo,string,int&)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

   at System.Runtime.Serialization.SerializationGuard.ThrowIfDeserializationInProgress(String , Int32& )
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo )
   at System.Diagnostics.Process.Start(String )
   at maui.MainPage.OnCounterClicked(Object sender, EventArgs e)

My repro project: maui-ea5dca2.zip

IMHO Process.Start should work with the AOT compiler, but that said it doesn't surprise me all that much that it doesn't, because Process.Start hasn't been available on platforms where the AOT compiler has existed (Process.Start doesn't work on iOS).

In any case, moving to dotnet/runtime, since that's where this should be fixed.

lambdageek commented 6 days ago

/cc @vitek-karas