maui: iOS Debugger Indicates App Has Terminated Immediately

Description

When using the iOS remote simulator in Visual Studio 17.3.0 Preview 5, after the initial use of the debugger, subsequent uses of the debugger fail to stay connected to the app, indicating “The app has been terminated”, even though the app successfully launches and stays running in the simulator.

Repro project: https://github.com/hunsra/iOSDebugger.App

Steps to Reproduce

  1. Create a new .NET MAUI App.
  2. Choose the “iPhone 13 Pro Max iOS 15.5” simulator from the list iOS Simulators targets.
  3. Debug the app.
  4. Press the stop debugging button on the toolbar.
  5. Debug the app again.
  6. Observe the app launch in the simulator, but the debugger detach and report “The app has been terminated.” in the Debug output window.

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15.5

Did you find any workaround?

If you close Visual Studio and re-open it, the debugger works once as described above.

Relevant log output

Build Log:
Build started...
1>------ Build started: Project: iOSDebugger, Configuration: Debug Any CPU ------
1>You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
1>Executing SayHello Task to establish a connection to a Remote Server. 
1>			Properties: 
1>				SessionId=b92a0820222943055e8a343c271a5ad24afb06e716c984bec440a9277f42317b, 
1>				Addresss=192.168.0.188, 
1>				SshPort=22, 
1>				TcpPort=50727, 
1>				User=randy, 
1>				AppName=iOSDebugger,
1>				VisualStudioProcessId=12564,
1>				ContinueOnDisconnected=False
1>Detected signing identity:
1>  Bundle Id: com.companyname.iosdebugger
1>  App Id: com.companyname.iosdebugger
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>iOSDebugger -> D:\Repos\iOSDebugger\iOSDebugger\bin\Debug\net6.0-ios\iossimulator-x64\iOSDebugger.dll
1>Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
1>/usr/bin/mdimport bin/Debug/net6.0-ios/iossimulator-x64/
2>------ Deploy started: Project: iOSDebugger, Configuration: Debug Any CPU ------
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Launching 'iOSDebugger' on 'iPhone 13 Pro Max iOS 15.5'...


Debug Log:
The app has been terminated.

Hot Reload Log:
17:05 47.75 iOSDebugger: Hot Reload session started
17:05 52.32 iOSDebugger: Hot Reload session complete


Xamarin Log:
Connection to 'mbp2017' completed successfully
The dotnet SDK is already installed. Version: '6.0.400-preview.22330.6'
dotnet validation completed
Sdk packs found: Microsoft.iOS.Sdk
The dotnet ios workload is already installed. Version: '15.4.430'
dotnet validation completed
Server Settings:
- mlaunch path: /Users/randy/Library/Caches/Xamarin/XMA/SDKs/dotnet/packs/Microsoft.iOS.Sdk/15.4.430/tools/bin/mlaunch
- Xcode version: 13.4
- Xcode path: /Applications/Xcode.app

Checking Xcode version compatibility...
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
SetSelectedDeviceAsync BEST Pixel 5 - API 31 (Android 12.0 - API 31)
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Starting Simulator to launch App...
The Simulator has been started to launch App...
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Build properties for D:\Repos\iOSDebugger\iOSDebugger\iOSDebugger.csproj: VisualStudioProcessId: 12564, RunConfiguration: Default, ArchiveOnBuild: False, ArchivePath: , IsAppDistribution: False, SolutionPath: D:\Repos\iOSDebugger\iOSDebugger.sln, SolutionName: iOSDebugger, MessagingVersion: 15.4.430, DeviceSpecificBuild: false, TargetiOSDevice: , _iOSRuntimeIdentifier: iossimulator-x64, IsHotRestartBuild: False, _DotNetRootRemoteDirectory: /Users/randy\Library\Caches\Xamarin\XMA\SDKs\dotnet/, ServerSshPort: 22, ServerTcpPort: 50727, ServerUser: randy, ContinueOnDisconnected: False, ServerAddress: 192.168.0.188
Starting Simulator to launch App...
The Simulator has been started to launch App...

Xamarin Hot Reload Log:
[5:05:41 PM]  (iOSDebugger) .NET 6 Project references .NET MAUI.
[5:05:41 PM]  (iOSDebugger) Starting Hot Reload session...
[5:05:42 PM]  XAML Hot Reload initializing...
[5:05:45 PM]  (iOSDebugger) Hot Reload: Initialized Agent.
[5:05:47 PM]  XAML Hot Reload Connected and Ready.
[5:06:01 PM]  (iOSDebugger) Stopping a Hot Reload session due to ExplicitlyEnded ...
[5:06:01 PM]  Stopped Hot Reload session.

VS bug #1747084

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 63 (8 by maintainers)

Most upvoted comments

This issue is being closed due to inactivity. If this issue is still affecting you, please follow the steps above to use the VS Feedback Tool to report the issue.

Looks like the bot is there to sync everything so we need to keep this issue open.

There is no fix. They didn’t fix anything that corresponds to this ticket. They just closed the ticket with the flag “Try latest version”.

@jeromelaban that’s a great question and I’m trying to figure out what happened here. It seems there’s some bot I’m unfamiliar with that is syncing issues between GitHub and Azure DevOps but I’m not sure what it’s doing or why.

I’m working on figuring that out. In theory we just need the Azure DevOps issue (https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1747084) but there’s something weird going on.

I’ll report back when I find out what’s happening.

In the meantime, just to be safe, don’t trust your microwave or electric toothbrush in case it’s the start of the robot uprising 😉

Here, I used the VS feedback tool. https://developercommunity.visualstudio.com/t/iOS-Debugger-Indicates-App-Has-Been-Te/10453966 the recording and all attachments are not visible for you guys but I did provided them.

@danroth27 Did not have time to do it. Do you know if it’s safe because I can’t share logs from this project it’s private.

Logs are collected and uploaded by default, but you can opt out of this if you want. It will make it much more difficult to figure out what’s going on though. It would be ideal if you can slim down your project to a minimal repro project that demonstrates the problem and that you can share.

Or if someone else following this issue has a reliable repro that they can share please go ahead and file your own VS feedback ticket. More data from more users helps.

This should be opened if it still is happening, but in the VS Feedback tool or in the macos repo.

I am also having the issue. I tried to change from Xamarin to .net MAUI because of this. I have seen similar issues dating back to 2016. This is ridiculous.

Considering just completely rebuilding my app using flutter because of this.

Can you please log this using the Report a Problem tool? That will enable us to get more information and prioritize easier. Go to the Visual Studio for Windows feedback tool or Visual Studio for Mac feedback tool to report the issue Close this bug, and consider adding a link to the VS Feedback issue so that others can follow its activity there.

This also happens to us. We have no way to get around this issue other than by debugging on an iOS simulator instead, but there are certain things that can only be tested on physical devices. We can run the app on device without the debugger attached, but then we can’t step through our code and we have to resort to putting Console.WriteLine() everywhere to see what’s happening (🤮).

I gave it a try tonight once again, and with my setup I was only able to reproduce this issue with the following crash report on iOS 16.3.1 iPhone 8 - VS 17.6.0 preview 1.0 - MAUI .NET7:

  "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGKILL"},
  "termination" : {"code":2343432205,"flags":6,"namespace":"FRONTBOARD","reasons":[
                  <RBSTerminateContext| domain:10 code:0x8BADF00D explanation:scene-create watchdog
                  transgression: application<com.companyname.mauiapp7>:492 exhausted real (wall clock)
                  time allowance of 0.68 seconds","ProcessVisibility: Foreground","ProcessState:
                  Running","WatchdogEvent: scene-create","WatchdogVisibility:
                  Foreground","WatchdogCPUStatistics: (","\"Elapsed total CPU time (seconds): 1.240
                  (user 1.240, system 0.000), 20% CPU\",","\"Elapsed application CPU time (seconds):
                  0.930, 15% CPU\"",") reportType:CrashLog maxTerminationResistance:Interactive>"]},

Where effectively the “crash” is due to the watchdog killing the application. In my case, I have tried in different scenarios:

  1. With low power mode -> the watchdog always kill the app in my device.
  2. With low battery percentage (and no low power mode) -> same thing.
  3. Sometimes, depending on the load on my device, the app is killed event with no low power mode and more than 50% of battery.

In my case my device is a bit old, it can be great to have feedback from people that commented on this issue with more recent devices, to check if the reason is the same for them.

If yes, this is very probable that the reason of this crash are the .NET cold start + application initial load.

To check the iOS native logs on crash: Settings -> Privacy & Security -> Analytics & Improvements -> Analytics Data -> Xamarin.PreBuilt.iOS-YYYY-MM-DD-HHmmss.ips.

I could find these two exceptions and logs which occurred right before the app crash. It is not wrote in the logs in every crash, because the apple main thread is also working with the RootViewController and it will crash the app sooner as the debugger stops at the exception in MAUI.

On the MAUI side in the UIApplication.Main(args, null, typeof(AppDelegate));:

**System.InvalidOperationException:** 'RootViewController cannot be null'

I think this is the cause of the crash. AppDelegate is extended from MauiUIApplicationDelegate which is not yet properly initialized and its property Window.RootViewController is null

On the iPhone device log:

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000004   x1: 0x0000000000000000   x2: 0x0000000000008b00   x3: 0x0000000000000000
    x4: 0x0000000000000000   x5: 0x00000000000000a1   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x000000016db3e8a8   x9: 0x0000000000000000  x10: 0x0000000102cb0340  x11: 0x0000120000001202
   x12: 0x0000000000001200  x13: 0x0000000000000000  x14: 0x0000000000001200  x15: 0x0000120000001200
   x16: 0x0000000000000131  x17: 0x0000000229371d40  x18: 0x0000000000000000  x19: 0x0000000102cb0328
   x20: 0x0000000102cb0278  x21: 0x00000002242e17e0  x22: 0x0000000000000000  x23: 0x0000000000000000
   x24: 0x0000000000008b00  x25: 0x0000000000008b01  x26: 0x0000000000008c00  x27: 0x0000000102cb0000
   x28: 0x0000000000000001   fp: 0x000000016db3e920   lr: 0x000000021acd706c
    sp: 0x000000016db3e890   pc: 0x000000020a86e41c cpsr: 0x60000000
   far: 0x00000001028f0000  esr: 0x56000080  Address size fault

Thread 0 is the com.apple.main-thread

I think a workaround till MAUI fixes it could be to initialize the MauiUIApplicationDelegate.Window.RootViewController , but I dont know yet how and where to do it.

Same here, app starts, splash is showing, then the app is terminated. If I start it manually from the phone then, it starts and works fine. Any workaround so far?