dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

xamarin_process_managed_exception caused by MainPage initialization #14626

Closed Kebechet closed 1 year ago

Kebechet commented 1 year ago

Description

I needed to override CreateWindow method where I put conditional create new MainPage because of Android deep links. This thing worked on all platforms (or at least it seemed so). I have tested in on: Windows debug Android debug, release and also real device iOS simulator, real device (debug from windows)

but the only case when it crashed whole application was when I published this into testflight in release configuration and through testflight I installed the app on my iphone and it immediately crashed.

I suppose it is a bug because it should behave the same way on all devices no matter the configuration, right ?

My code:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
    }

    protected override Window CreateWindow(IActivationState? activationState)
    {
        MainPage ??= new MainPage();

        return base.CreateWindow(activationState);
    }
}

Steps to Reproduce

1 publish this project in release configuration into testflight 2 app will crash on start on your device

Link to public reproduction project repository

https://github.com/Kebechet/BlazorHybridBug/

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS - all

Did you find any workaround?

I need to specify the MainPage also in the constructor like:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
                MainPage = new MainPage();
    }

    protected override Window CreateWindow(IActivationState? activationState)
    {
        MainPage ??= new MainPage();

        return base.CreateWindow(activationState);
    }
}

Relevant log output

CoreFoundation
__exceptionPreprocess
libobjc.A.dylib
objc_exception_throw
SatisFIT.Client.App
xamarin_process_managed_exception runtime.m:2425
SatisFIT.Client.App
native_to_managed_trampoline_3(objc_object*, objc_selector*, _MonoMethod**, objc_object*, objc_object*, unsigned int) registrar.mm:189
SatisFIT.Client.App
-[AppDelegate application:didFinishLaunchingWithOptions:] registrar.mm:15556
UIKitCore
-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:]
UIKitCore
-[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:]
UIKitCore
-[UIApplication _runWithMainScene:transitionContext:completion:]
UIKitCore
-[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:]
UIKitCore
_UIScenePerformActionsWithLifecycleActionMask
UIKitCore
-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
UIKitCore
-[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:]
UIKitCore
-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
UIKitCore
-[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:]
UIKitCore
-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]
UIKitCore
+[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:]
UIKitCore
_UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion
UIKitCore
-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]
UIKitCore
-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]
UIKitCore
-[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:]
UIKitCore
-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]
UIKitCore
-[UIApplication workspace:didCreateScene:withTransitionContext:completion:]
UIKitCore
-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:]
FrontBoardServices
-[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:]
FrontBoardServices
-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]
FrontBoardServices
-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
FrontBoardServices
-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]
libdispatch.dylib
_dispatch_client_callout
libdispatch.dylib
_dispatch_block_invoke_direct
FrontBoardServices
__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
FrontBoardServices
-[FBSSerialQueue _targetQueue_performNextIfPossible]
FrontBoardServices
-[FBSSerialQueue _performNextFromRunLoopSource]
CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
CoreFoundation
__CFRunLoopDoSource0
CoreFoundation
__CFRunLoopDoSources0
CoreFoundation
__CFRunLoopRun
CoreFoundation
CFRunLoopRunSpecific
GraphicsServices
GSEventRunModal
UIKitCore
-[UIApplication _run]
UIKitCore
UIApplicationMain
SatisFIT.Client.App
xamarin_UIApplicationMain bindings.m:126
SatisFIT.Client.App
do_icall interp.c:2321
SatisFIT.Client.App
do_icall_wrapper interp.c:2361
SatisFIT.Client.App
interp_exec_method interp.c:3885
SatisFIT.Client.App
interp_runtime_invoke interp.c:2122
SatisFIT.Client.App
mono_jit_runtime_invoke mini-runtime.c:3561
SatisFIT.Client.App
mono_runtime_invoke_checked object.c:2415
SatisFIT.Client.App
do_exec_main_checked object.c:0
SatisFIT.Client.App
mono_jit_exec driver.c:1365
SatisFIT.Client.App
xamarin_main monotouch-main.m:490
SatisFIT.Client.App
main main.arm64.mm:81
dyld
start
PureWeen commented 1 year ago

@Kebechet you need to return the main page with a new window that you've created. So, for your code here

https://github.com/Kebechet/BlazorHybridBug/blob/main/BlazorHybridApp/BlazorHybridApp/App.xaml.cs#L12

    protected override Window CreateWindow(IActivationState? activationState)
    {
        return new Window(new MainPage());
    }
ghost commented 1 year ago

Hi @Kebechet. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Kebechet commented 1 year ago

@Kebechet you need to return the main page with a new window that you've created. So, for your code here

https://github.com/Kebechet/BlazorHybridBug/blob/main/BlazorHybridApp/BlazorHybridApp/App.xaml.cs#L12

    protected override Window CreateWindow(IActivationState? activationState)
    {
        return new Window(new MainPage());
    }

but even though your solution is the right way to go, there is still the problem of inconsistency. Because the only place where it was crashing was deployed ios application in Testflight. It didnt crash in simulator, in local ios device or on other platforms like Android or windows.

mattleibow commented 1 year ago

This issue was moved to xamarin/xamarin-macios#19388