Bug 18432 - NSDecimalNumber(string stringValue) throws NullReferenceException when called from F#
Summary: NSDecimalNumber(string stringValue) throws NullReferenceException when called...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-03-17 16:11 UTC by Larry O'Brien
Modified: 2014-03-17 16:30 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 Larry O'Brien 2014-03-17 16:11:29 UTC
The NSDecimalNumber ctor NSDecimalNumber(string numberValue), which binds "initWithString:", throws an NRE :

    > let n = new NSDecimalNumber("10.0");;
System.NullReferenceException: Object reference not set to an instance of an object
  at MonoTouch.ObjCRuntime.Class.Register (System.Type type) [0x00000] in <filename unknown>:0
  at MonoTouch.ObjCRuntime.Class.GetHandle (System.Type type) [0x00000] in <filename unknown>:0
  at MonoTouch.Foundation.NSObject.AllocIfNeeded () [0x00000] in <filename unknown>:0
  at MonoTouch.Foundation.NSObject..ctor (MonoTouch.Foundation.NSObjectFlag x) [0x00000] in <filename unknown>:0
  at MonoTouch.Foundation.NSValue..ctor (MonoTouch.Foundation.NSObjectFlag t) [0x00000] in <filename unknown>:0
  at MonoTouch.Foundation.NSNumber..ctor (MonoTouch.Foundation.NSObjectFlag t) [0x00000] in <filename unknown>:0
  at MonoTouch.Foundation.NSDecimalNumber..ctor (System.String numberValue) [0x00000] in <filename unknown>:0
  at <StartupCode$FSI_0004>.$FSI_0004.main@ () [0x00000] in <filename unknown>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
Stopped due to error
Comment 1 Larry O'Brien 2014-03-17 16:13:24 UTC
Wait... Is NSDecimalNumber not supposed to be bound or something?

> let n = NSDecimalNumber.One;;

val n : NSDecimalNumber = null

> n;;
val it : NSDecimalNumber = null
> let m = NSDecimalNumber.MaxValue;;

val m : NSDecimalNumber = null

> let n = NSDecimalNumber.MinValue;;

val n : NSDecimalNumber = null
Comment 2 Larry O'Brien 2014-03-17 16:25:46 UTC
This appears to be peculiar to F#, or maybe even the fsharp shell. When executed in a "real" C# program, the constructor and factory methods work.
Comment 3 Sebastien Pouliot 2014-03-17 16:30:42 UTC
[[16:14:12]  <lobrien>	 Is MonoTouch.Foundation.NSDecimalNumber not supposed to be bound or something? Neither its constructors nor its factory methods seem to produce objects.
[16:19:44]  <spouliot>	 lobrien: the error is weird, does the same happens from C# ?
[16:20:03]  <lobrien>	 lemme check
[16:20:34]  <spouliot>	 we have test creating every type of NSObject and they do not trigger an error when registering the class
[16:23:54]  <lobrien>	 no
[16:23:59]  <lobrien>	 i mean, no, it works in C#
[16:24:11]  <lobrien>	 That's weird.
[16:24:25]  <spouliot>	 Assert.NotNull (NSDecimalNumber.One, "One");
[16:24:29]  <spouliot>	 ^ works for me
[16:24:46]  <spouliot>	 from where did you run this ? sim, device ?
[16:26:35]  <lobrien>	 I used the fsharp shell. When I just did it in C# it worked fine.
[16:29:28]  <spouliot>	 the shell(s) likely do not initialize anything related to iOS/OSX
[16:30:06]  <spouliot>	 that might be a good feature request (to the shell) but not a bug for XI :)
[16:30:11]  <lobrien>	 yes