locked
Segmentation Fault receiving message on WatchOS with debugger attached RRS feed

  • Question

  • User97755 posted

    I am developing an Apple Watch app in Xamarin to connect to the iOS side of my existing Xamarin.Forms app. This issue started appearing on the latest versions of Xcode and Xamarin.

    When I run the watch project and send a message from the phone using WCSession.DefaultSession.SendMessage(...), the watch app crashes. This usually happens the second time a message is sent, although it varies. When the crash occurs, the debugger immediately exits and no relevant log is printed. It seems to crash in some internal logic, not on any line of my code. I sometimes (~5% of the time) get a crash file generated in "/Users/johns/Library/Logs/DiagnosticReports/", which is how I know the crash is due to a segmentation fault. If I do not have the debugger attached, the crash does not occur.

    I create a small sample project to show/reproduce the issue. The iOS app has a button that sends a message to the watch. Both projects set a WCSessionDelegate and activate the WCSession on startup. The behavior was reproduced on both an iMac and a Macbook. I will attach the sample project and one of the crash logs.

    Any help would be appreciated. Thanks.

    My Environment: === Visual Studio Community 2019 for Mac ===

    Version 8.3.10 (build 2) Installation UUID: ca9efe8c-cd51-499b-83d0-27b4a235045b GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)

    Package version: 604000208
    

    === Mono Framework MDK ===

    Runtime: Mono 6.4.0.208 (2019-06/07c23f2ca43) (64-bit) Package version: 604000208

    === NuGet ===

    Version: 5.3.0.6192

    === .NET Core SDK ===

    SDK: /usr/local/share/dotnet/sdk/3.0.100/Sdks SDK Versions: 3.0.100 3.0.100-preview8-013656 2.1.701 2.1.700 2.1.505 2.1.301 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks

    === .NET Core Runtime ===

    Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 3.0.0 3.0.0-preview8-28405-07 2.1.13 2.1.12 2.1.11 2.1.9 2.1.1

    === Xamarin.Profiler ===

    Version: 1.6.12.26 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

    === Updater ===

    Version: 11

    === Xamarin.Android ===

    Version: 10.0.6.2 (Visual Studio Community) Commit: xamarin-android/d16-3/c407838 Android SDK: /Users/johns/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 8.1 (API level 27)

    SDK Tools Version: 26.1.1 SDK Platform Tools Version: 29.0.4 SDK Build Tools Version: 27.0.3

    Build Information: Mono: mono/mono/2019-06@476d72b9e32 Java.Interop: xamarin/java.interop/d16-3@5836f58 LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94 LibZip: nih-at/libzip/rel-1-5-1@b95cf3fd ProGuard: xamarin/proguard/master@905836d SQLite: xamarin/sqlite/3.27.1@8212a2d Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

    === Microsoft Mobile OpenJDK ===

    Java SDK: /Users/johns/Library/Developer/Xamarin/jdk/microsoftdistopenjdk_8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

    === Android SDK Manager ===

    Version: 1.4.0.65 Hash: c33b107 Branch: remotes/origin/d16-3 Build date: 2019-11-19 20:33:22 UTC

    === Android Device Manager ===

    Version: 1.2.0.116 Hash: d2b2af0 Branch: remotes/origin/d16-3 Build date: 2019-11-19 20:33:42 UTC

    === Xamarin Inspector ===

    Version: 1.4.3 Hash: db27525 Branch: 1.4-release Build date: Mon, 09 Jul 2018 21:20:18 GMT Client compatibility: 1

    === Xamarin Designer ===

    Version: 16.3.0.256 Hash: 8a223bfd7 Branch: remotes/origin/d16-3 Build date: 2019-11-01 21:02:02 UTC

    === Apple Developer Tools ===

    Xcode 11.2.1 (15526.1) Build 11B500

    === Xamarin.Mac ===

    Version: 6.6.0.12 (Visual Studio Community) Hash: e3c2b406d Branch: xcode11.2 Build date: 2019-11-01 00:12:07-0400

    === Xamarin.iOS ===

    Version: 13.6.0.12 (Visual Studio Community) Hash: e3c2b406d Branch: xcode11.2 Build date: 2019-11-01 00:12:08-0400

    === Build Information ===

    Release ID: 803100002 Git revision: add3a4998a5cb5b081e0404e1fe13acfecb7801d Build date: 2019-11-20 13:35:15+00 Build branch: release-8.3 Xamarin extensions: 79c69708816813b498283eeda7bcb4d464433a04

    === Operating System ===

    Mac OS X 10.15.1 Darwin 19.0.0 Darwin Kernel Version 19.0.0 Thu Oct 17 16:17:15 PDT 2019 root:xnu-6153.41.3~29/RELEASEX8664 x86_64

    Friday, November 22, 2019 7:45 PM

All replies

  • User97755 posted

    It's also worth noting that I re-created the project in Xcode and Objective-C, and saw no issues.

    Friday, November 22, 2019 7:48 PM
  • User97755 posted

    I made a bug report here https://github.com/xamarin/Xamarin.Forms/issues/8629 as well, since I wasn't sure the best place to post this.

    Friday, November 22, 2019 7:56 PM
  • User97755 posted

    Getting a similar crash on startup in the Xamarin sample project https://github.com/xamarin/ios-samples/tree/master/watchOS/SimpleWatchConnectivity

    Friday, November 22, 2019 10:02 PM
  • User51603 posted

    @SpruceGoose429 I think I have the same issue. Which watch series/watch os version are you trying to debug? Debugger stops working and I am getting a crash when I execute WCSession.ActivateSession() in ExtensionDelegate class. I am using the latest version of xamarin.

    Tuesday, November 26, 2019 12:29 PM
  • User97755 posted

    I was getting the same crash on "WCSession.ActivateSession()" in the ExtensionDelegate class. It didn't crash right on that line but did shortly after. I had better luck when I added "WCSession.ActivateSession()" in the AppDelegate of the phone project. Now I can sometimes get past watch startup and receive messages from the phone. But sending messages seem to be a no go.

    I tried a couple of different simulators. The majority of my testing was using the iPhone 11 Pro with iOS 13.2 and the Apple Watch Series 5 - 40mm with watchOS 6.1.

    Tuesday, November 26, 2019 10:03 PM
  • User97755 posted

    Here is a new zip with more information about the bug. I made some changes to the sample project and included other sample projects as well. I also included additional logs and some test step information.

    It seems like Xamarin watch development is completely blocked right now with all of these segmentation faults. It took me a long time to get reproduction steps and information on one way to trigger it. Hope this helps get closer to a solution.

    Tuesday, December 3, 2019 11:17 PM
  • User97755 posted

    Interesting. When I run the "WCSessionTest" sample project (that I uploaded here) with the debugger attached to the phone project instead of the watch, I get tons of logs like this in the application output.

    [WC] WCSession counterpart app not installed

    Furthermore, going to the "Watch" app on the phone simulator - it looks like my watch project isn't fully installed. There is a loading circle next to the app and it is under "AVAILABLE APPS" instead of being in the section for installed apps. I'll attach a screenshot. Installing my app from Microsoft AppCenter doesn't have this behavior. From AppCenter, it appears to be installed normally.

    I'll also upload my "Application Output" logs from my test on the phone simulator.

    For this test, I first opened the watch app. I then ran the iOS project through Visual Studio on the paired iPhone simulator, waited for boot, and hit the "Send message to watch" button a few times. As I have said before, the watch app does not crash when I test without the debugger on the watch project like this.

    Wednesday, December 4, 2019 6:41 PM
  • User51603 posted

    @SpruceGoose429 did you find any solution?

    Tuesday, June 9, 2020 7:28 AM