Bug 29178 - Mac application crashes when call NSWorkspace.SharedWorkspace.OpenUrls
Summary: Mac application crashes when call NSWorkspace.SharedWorkspace.OpenUrls
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.10.0
Hardware: All Mac OS
: High normal
Target Milestone: 2.4.0 (C6)
Assignee: Chris Hamons
Depends on:
Reported: 2015-04-17 04:28 UTC by Denis Davydov
Modified: 2015-10-01 15:05 UTC (History)
3 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 Denis Davydov 2015-04-17 04:28:56 UTC
I want open Url exactly in Safari browser.

NSUrl[] nsUrl = new NSUrl[] {

var descriptor =NSAppleEventDescriptor.DescriptorWithString("/Users/<user_name>/Downloads/<file_name>"));
NSWorkspace.SharedWorkspace.OpenUrls(nsUrl, "com.apple.Safari", NSWorkspaceLaunchOptions.Default, descriptor, new string[0]);

As result:
Browser is opened but my app crashes immediately:


  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) MonoMac.ObjCRuntime.Class.class_getMethodImplementation (intptr,intptr) <IL 0x00026, 0xffffffff>
  at MonoMac.Foundation.NSObject.IsUserType (intptr) <IL 0x0000e, 0x0005f>
  at MonoMac.Foundation.NSObject.ReleaseManagedRef () <IL 0x00009, 0x0003f>
  at MonoMac.Foundation.NSObject.Dispose (bool) <IL 0x00036, 0x000c3>
  at MonoMac.Foundation.NSObject.Dispose () <IL 0x00003, 0x00034>
  at MonoMac.AppKit.NSWorkspace.OpenUrls (MonoMac.Foundation.NSUrl[],string,MonoMac.AppKit.NSWorkspaceLaunchOptions,MonoMac.Foundation.NSAppleEventDescriptor,string[]) <IL 0x000cf, 0x003b7>
  at OS33.Mac.OsXComponents.ApplicationManager.OpenUrl (string) [0x0003d] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/OsXComponents/ApplicationManager.cs:34
  at OS33.Mac.Drive.Presentation.DriveApplicationPresenter.OnOpenCompanyUrl () [0x00012] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/DrivePresentation/DriveApplicationPresenter.cs:745
  at OS33.Mac.Drive.Model.EventHelper.Raise (System.Action) [0x0000e] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/Drive.Model/EventHelper.cs:14
  at OS33.Mac.Drive.Presentation.DrivePresentersDirector.CompanyUrlClick () [0x00007] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/DrivePresentation/DrivePresentersDirector.cs:110
  at OS33.Mac.Drive.Model.EventHelper.Raise (System.Action) [0x0000e] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/Drive.Model/EventHelper.cs:14
  at OS33.Mac.TourView.<TourView>m__1 () [0x00006] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/OS33App/TourView.cs:33
  at OS33.Mac.Drive.Model.EventHelper.Raise (System.Action) [0x0000e] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/Drive.Model/EventHelper.cs:14
  at OS33.Mac.TourWindowController.<LoadWindow>m__0 () [0x00006] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/OS33App/TourWindowController.cs:99
  at OS33.Mac.Drive.Model.EventHelper.Raise (System.Action) [0x0000e] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/Drive.Model/EventHelper.cs:14
  at OS33.Mac.CustomViews.CustomNSTextField.MouseDown (MonoMac.AppKit.NSEvent) [0x0000e] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/OS33App/CustomViews/CustomNSTextField.cs:58
  at (wrapper dynamic-method) object.[OS33.Mac.CustomViews.CustomNSTextField.Void MouseDown(MonoMac.AppKit.NSEvent)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSEvent) <IL 0x00011, 0x00071>
  at (wrapper native-to-managed) object.[OS33.Mac.CustomViews.CustomNSTextField.Void MouseDown(MonoMac.AppKit.NSEvent)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSEvent) <IL 0x000ba, 0xffffffff>
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <IL 0x000a4, 0xffffffff>
  at MonoMac.AppKit.NSApplication.Main (string[]) <IL 0x00041, 0x000f3>
  at OS33.Mac.MainClass.Main (string[]) [0x00007] in /Users/alex/Documents/GitRepositories/OS33Mac/TFSRepo/OS33.Mac/OS33App/Main.cs:12
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

Debug info from gdb:

Comment 1 Chris Hamons 2015-04-17 09:48:51 UTC

The following is code to open a url in safari:

NSWorkspace.SharedWorkspace.OpenURL (NSUrl.FromFilename (filename), NSWorkspaceLaunchOptions.Default, new NSDictionary (), out e);

Please let me know if that simpler code doesn't work for you.
Comment 2 Denis Davydov 2015-04-20 06:23:42 UTC
there is not   OpenUrl with mentioned signature  in NSWorkspace .


[Export("openURL:"), CompilerGenerated]
public virtual bool OpenUrl(NSUrl url);

And this method opens Url in default browser (in chrome for example).
I need to open url exactly in Safari.
Comment 3 Chris Hamons 2015-04-20 12:35:20 UTC
It turns out that OpenURLs is broken. You are correct. My apologies.

Here is a work around for you:


Paste in NSWorkspacePatch and use NSWorkspace.SharedWorkspace.OpenUrls as shown.
Comment 4 Chris Hamons 2015-04-20 15:43:05 UTC
Fixed in master / 1419967816518b97bfa2e71e1c9a44be1186d550. This will be in XM 2.2, later this year.

QA - This line is what crashes:

NSWorkspace.SharedWorkspace.OpenUrls (new [] { new NSUrl ("https://www.google.com/") },
"com.Apple.Safari", NSWorkspaceLaunchOptions.Default, NSAppleEventDescriptor.NullDescriptor, new string[] {});
Comment 5 Rajneesh Kumar 2015-10-01 15:05:41 UTC
I have checked this issue with the cycle 6 builds XS 5.10 (build 811) + X.M + Mono and observed that this issue has been fixed and no longer exist with this build. Now, I observed that Mac application does't crashes and it opens https://www.google.co.in in Safari browser successfully.

Screencast: http://www.screencast.com/t/xzbD46Fgl

This issue has been fixed hence I am closing this issue.


Environment Info:

=== Xamarin Studio ===

Version 5.10 (build 811)
Installation UUID: 0b7eaebc-a0ed-4b58-81df-91e378cad28c
	Mono 4.2.1 (explicit/328e048)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010059

=== Xamarin.Profiler ===

Location: /Applications/XamarinProfiler.Mac.app/Contents/MacOS/XamarinProfiler.Mac

=== Apple Developer Tools ===

Xcode 7.0 (8227)
Build 7A220

=== Xamarin.Mac ===

Version: (Starter Edition)

=== Xamarin.iOS ===

Version: (Starter Edition)
Hash: d8e9592
Branch: master
Build date: 2015-09-18 23:22:05-0400

=== Xamarin.Android ===

Version: (Starter Edition)
Android SDK: /Users/Admin_Mac/Desktop/Anddk/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)

SDK Tools Version: 24.3.4
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 22.0.1

Java SDK: /usr
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.1
Location: /Applications/Xamarin Android Player.app

=== Build Information ===

Release ID: 510000811
Git revision: 34cd31ea72536afab530c14d9220b286075e83cd
Build date: 2015-09-30 10:40:37-04
Xamarin addins: 8e6fccfc0c19a7e0b7b11be925f09751d827eb5c
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.11.0
Darwin Admin-Macs-Mac-mini.local 15.0.0 Darwin Kernel Version 15.0.0
    Wed Aug 26 16:57:32 PDT 2015
    root:xnu-3247.1.106~1/RELEASE_X86_64 x86_64