Bug 17118 - Xamarin.Mac crash
Summary: Xamarin.Mac crash
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Other ()
Version: 1.6.19
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Aaron Bockover [MSFT]
Depends on:
Reported: 2014-01-08 10:24 UTC by Rodrigo Kumpera
Modified: 2014-02-17 11:09 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Rodrigo Kumpera 2014-01-08 10:24:21 UTC
This was reported as a Xam.Mac crasher:

Comment 1 Keith Boynton 2014-01-09 16:54:57 UTC
Hi, what is the expected turnaround on this, do you need any more information?
Comment 2 Keith Boynton 2014-01-11 13:20:19 UTC
I've just received confirmation that the version contained in the AppStore now crashes too.

This is highly likely to be a Mavericks related issue, the app has not been crashing at all prior to Mavericks but now users are reporting crashes and they are all Mavericks related.

My release path on the Mac is completely blocked due to this bug.

Please let me know if there is any more information you need...?
Comment 3 Keith Boynton 2014-01-12 12:16:16 UTC
Looking at the thread that Rodrigo linked, I would suggest this thread is much more relevant.


This issue has been around for quite a while now and I'm getting nothing substantial back from Xamarin.

Come on guys step up!
Comment 7 Chris Hamons 2014-01-23 09:58:40 UTC
After analysis and discussion with another engineer, we believe we've found an issue with your submitted example that may explain the crashes you've been seeing.

See GUIHelper.cs line 96:

        public static void ShowUnboundMessage(String title, String message, MessageType type, MessageButtons buttons)
            NSAlert oAlert = new NSAlert();                 
            // Set the type
            NSAlertStyle style = SetMessageBoxType(type);

            // Set the buttons
                oAlert = SetMessageBoxButtons(buttons, oAlert);

            // Show the message box and capture
            oAlert.MessageText = title;
            oAlert.InformativeText = message;
            oAlert.AlertStyle = style;

As we are invoking to the main thread, I belive this method (and other methods that use NSAlert) can be called on backgroud threads.

The rule with UI objects on many platforms, including Xamarin.Mac, is that you should only instance and call methods\properties on UI objects on the main (UI) thread.
- The code above allocated an NSAlert on whatever thread we're on, then uses it to invoke to the main thread to so some work. This is already incorrect.
- Inside the invoke, we set oAlert to a new NSAlert possibly. If so, our instance could be cleaned up once we've lost the last reference to it.
- We then call RunModal (on whatever thread we're on). If this is a background thread, this is not valid.

In general the correct programming pattern is to package up whatever information you need on your background thread and make one call to invoke to main thread.
That thread should be the only one that instances NSAlerts (and other GUI objects), and calls RunModel. You background thread will wait in the Invoke until the modal dialog is complete.

I believe by rewritting your helpers in GUIHelpers to follow this pattern your issue should be resolved. Give that a try and get back to me (with the new code) if you are still having an issue.
Comment 8 Keith Boynton 2014-02-05 17:23:56 UTC
I've done some more testing around this and the problem doesn't appear to be main thread related from what I can see.

I've changed the EmptyPlaylistToolStripMenuItemClick method to read like this:

public void EmptyPlaylistToolStripMenuItemClick()
      var alert = new NSAlert ()
          MessageText = "Test",
          InformativeText = "Testing"

      var responseAlert = alert.RunModal();
      if (responseAlert == 1000) { }

As you can see, called from the main thread, nothing clear going on and it still crashes just the same intermittently.

I have a zip of the project with this code change in it but don't want to attach it to this bug for IP reasons.
Comment 9 Chris Hamons 2014-02-05 18:46:46 UTC
I'm glad you were able to reduce the size of the reproduction case. 

Could you either:

a) (Preferably) Try to reproduce the issue outside of your entire application, in a simple "new project" with the above code and any supporting code.
b) E-mail me directly at chris.hamons@xamarin.com with a location you've uploaded the zip file.

Comment 10 Keith Boynton 2014-02-06 03:18:45 UTC
Hi Chris,

Emailed you.

Thanks for your quick attention!
Comment 11 Chris Hamons 2014-02-11 09:25:56 UTC
This has been fixed by a previous change in the beta channel. Keith was able to confirm via e-mail.
Comment 12 Todd Aspeotis 2014-02-15 19:21:33 UTC
I put myself on the CC list to keep an eye on this bug. I have a Xamarin.Mac application that appears to crash for no reason and I've checked for reference counting issues (which I'm always mindful of but sometimes they slip in) and everything seems okay.

Is it possible to get more detail on what the issue is and whether there's any way to mitigate it in the latest stable version of Xamarin.Mac? Right now I'm building with Xamarin.Mac 1.2 since 1.4 broke displaying sheets and whatever the current release is seems to have this bug.

Comment 13 Keith Boynton 2014-02-16 06:26:08 UTC
Interestingly I wanted to know more detail on what the actual issue was too but I've been unable to get any further info from the team either.

What concerns me is that even though this NSAlert related issue seems to be resolved there are still a lot of intermittent crashes that happen in my application that did not happen prior to Mavericks.

I've been in a state of being unable to release a Mac version of my application since November last year.

I'm trying to collate more information so I can raise these other issues with the Xamarin team too .
Comment 14 Chris Hamons 2014-02-17 08:39:26 UTC
I haven't forgotten about getting you guys more information.

Todd - Have you filed bugs against the 1.4 issues?
Keith - If you still have other crashes using the Beta version of Xam.Mac, please try to create a reproduction case and files bugs. We can't fix what we don't know about. :)
Comment 15 Keith Boynton 2014-02-17 11:09:09 UTC
Hi Chris,

I can provide the current solution along with crash logs. Where would you like me to send them?