Bug 12597 - Managed methods returning strings to native crash with null value
Summary: Managed methods returning strings to native crash with null value
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.4.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Aaron Bockover [MSFT]
Depends on:
Reported: 2013-06-07 13:45 UTC by Aaron Bockover [MSFT]
Modified: 2013-06-20 12:52 UTC (History)
2 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 Aaron Bockover [MSFT] 2013-06-07 13:45:54 UTC
When a managed method is invoked by the native runtime that returns a System.String (to be marshalled as an NSString), if the string value is null, a crash will occur (ArgumentNullException).

This is because the generated IL invokes the NSString(System.String) constructor, which in turn checks if the argument is null, and throws if so.

An example crash can be found here:

A static method should be invoked by the IL that returns null or an instance of NSString instead.
Comment 1 Aaron Bockover [MSFT] 2013-06-07 14:12:09 UTC
This should now be fixed: https://github.com/mono/monomac/commit/21e257f823d5e0748c9c97ac7dec473d4931c074
Comment 2 Mohit Kheterpal 2013-06-20 12:52:43 UTC
Today we have checked this issue on following builds :

XS 4.0.8 (build 2)
Mono 2.10.12
Xam.mac 1.4.22

Now we are not getting any error when we enter any name which does not exist in the list. 

Hence closing this issue. Changing its status to verified.