Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Segmentation Fault receiving message on WatchOS with debugger attached

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 (d16-3 / 08809f5b)

Package version: 604000208

=== Mono Framework MDK ===

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

=== NuGet ===


=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.0.100/Sdks
SDK Versions:
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:

=== Xamarin.Profiler ===

Location: /Applications/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: (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/[email protected]
Java.Interop: xamarin/java.interop/[email protected]
LibZipSharp: grendello/LibZipSharp/[email protected]
LibZip: nih-at/libzip/[email protected]
ProGuard: xamarin/proguard/[email protected]
SQLite: xamarin/sqlite/[email protected]
Xamarin.Android Tools: xamarin/xamarin-android-tools/[email protected]

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/johns/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
Android Designer EPL code available here:

=== Android SDK Manager ===

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

=== Android Device Manager ===

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 ===

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: (Visual Studio Community)
Hash: e3c2b406d
Branch: xcode11.2
Build date: 2019-11-01 00:12:07-0400

=== Xamarin.iOS ===

Version: (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/RELEASE_X86_64 x86_64


  • SpruceGoose429SpruceGoose429 USMember ✭✭

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

  • SpruceGoose429SpruceGoose429 USMember ✭✭

    I made a bug report here as well, since I wasn't sure the best place to post this.

  • SpruceGoose429SpruceGoose429 USMember ✭✭

    Getting a similar crash on startup in the Xamarin sample project

  • OnurHazarOnurHazar USUniversity ✭✭✭

    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.

  • SpruceGoose429SpruceGoose429 USMember ✭✭

    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.

  • SpruceGoose429SpruceGoose429 USMember ✭✭

    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.

  • SpruceGoose429SpruceGoose429 USMember ✭✭

    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.

  • OnurHazarOnurHazar USUniversity ✭✭✭

    @SpruceGoose429 did you find any solution?

Sign In or Register to comment.