Bug 19826 - Linker removing something that causes usage of Selector.Name to crash the app.
Summary: Linker removing something that causes usage of Selector.Name to crash the app.
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.8.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2014-05-15 12:58 UTC by Jon Lipsky
Modified: 2015-02-20 01:40 UTC (History)
7 users (show)

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


Attachments
Solution to reproduce the issue. (24.25 KB, application/zip)
2014-05-15 12:58 UTC, Jon Lipsky
Details


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:
Status:
VERIFIED FIXED

Description Jon Lipsky 2014-05-15 12:58:56 UTC
Created attachment 6821 [details]
Solution to reproduce the issue.

When I run my app with linking turned on, my app will crash when it access the the "Name" property on the Selector class. 

First, I have attached a sample that can be used to reproduce the problem.  Simply launch the app with the "Release" configuration, make sure the text box has the focus and press the "escape" key.

Second, as a reference, I have included the relevent Xamarin products currently installed on my machine that were used to reproduce this issue:

Xamarin Studio
Version 5.0 (build 866)
Installation UUID: fe297843-d0ad-4619-84e2-c1ff4238ce46
Runtime:
	Mono 3.4.0 ((no/c3fc3ba)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000204

Apple Developer Tools
Xcode 5.1.1 (5085)
Build 5B1008

Xamarin.Mac
Xamarin.Mac: 1.8.0.8

Build Information
Release ID: 500000866
Git revision: 89cfcdd28a9a64d4ddc606f8c4f8e6aaafad610a
Build date: 2014-05-12 14:59:13-04
Xamarin addins: e92a35a9280dede5cbdceaaec0c40c06c163546e

Operating System
Mac OS X 10.8.5
Darwin jlipsky-retina.local 12.5.0 Darwin Kernel Version 12.5.0
    Sun Sep 29 13:33:47 PDT 2013
    root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
Comment 1 Jon Lipsky 2014-05-15 13:00:56 UTC
As a bit of additional information, when you run the sample, here is the exception you'll get

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStringAnsi (intptr) <0xffffffff>
  at System.Runtime.InteropServices.Marshal.PtrToStringAuto (intptr) <0x0001b>
  at MonoMac.ObjCRuntime.Selector.get_Name () <0x00023>
  at XamMacLinkingIssue.MMNumberFieldDelegate.DoCommandBySelector (MonoMac.AppKit.NSControl,MonoMac.AppKit.NSTextView,MonoMac.ObjCRuntime.Selector) <0x00027>
  at (wrapper dynamic-method) object.[XamMacLinkingIssue.MMNumberFieldDelegate.Boolean DoCommandBySelector(MonoMac.AppKit.NSControl, MonoMac.AppKit.NSTextView, MonoMac.ObjCRuntime.Selector)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSControl,MonoMac.AppKit.NSTextView,MonoMac.ObjCRuntime.Selector) <0x00033>
  at (wrapper native-to-managed) object.[XamMacLinkingIssue.MMNumberFieldDelegate.Boolean DoCommandBySelector(MonoMac.AppKit.NSControl, MonoMac.AppKit.NSTextView, MonoMac.ObjCRuntime.Selector)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSControl,MonoMac.AppKit.NSTextView,MonoMac.ObjCRuntime.Selector) <0xffffffff>
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0xffffffff>
  at MonoMac.AppKit.NSApplication.Main (string[]) <0x00097>
  at XamMacLinkingIssue.MainClass.Main (string[]) <0x00017>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2014-05-30 20:26:36 UTC
Many thanks for the report and the test case! Just to get a little start on this, I did some guess-and-check to narrow the problem down, and found that there's one method in particular that the linker shouldn't have removed:

`MonoMac.ObjCRuntime.SelectorMarshaler.GetInstance()`


## Workaround

A workaround for this problem is to tell the linker to skip that method.

1. Add the following to the project in an XML file (for example named `linker.xml`):

<linker>
  <assembly fullname="XamMac">
    <type fullname="MonoMac.ObjCRuntime.SelectorMarshaler">
      <method name="GetInstance" />
    </type>
  </assembly>
</linker>


2. Under "Project Options -> Mac OS X Packaging -> Advanced [tab] -> Advanced Mono Bundling Options -> Extra Arguments" add:

--xml=${ProjectDir}/linker.xml
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-12-04 03:08:11 UTC
This should be fixed with the runtime unification (MonoMac.ObjCRuntime.SelectorMarshaler doesn't even exist anymore).
Comment 4 Chris Hamons 2015-02-19 18:30:40 UTC
This appears to have been fixed in XM 1.12 (In Alpha/Beta channel).
Comment 5 Prashant manu 2015-02-20 01:40:08 UTC
Today, I have checked this issue with steps mentioned in bug description and observed that now this is not exists attached sample is working fine in release mode without any error.

Hence closing this issue.

Environment info:=== Xamarin Studio ===

Version 5.7.2 (build 2)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.Mac ===

Version: 1.12.0.4 (Trial Edition)

=== Xamarin.Android ===

Version: 4.20.0.28 (Starter Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		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)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.iOS ===

Version: 8.6.1.24 (Starter Edition)
Hash: 1ee873c
Branch: 
Build date: 2015-01-31 17:42:21-0500

=== Build Information ===

Release ID: 507020002
Git revision: d6231e6325f274cea59da478410f561312c5b401
Build date: 2015-02-17 19:04:38-05
Xamarin addins: b212fd66838b0d6e2435966e541e66ab9c988698

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64