Bug 14977 - System.TypeInitializationException + System.NullReferenceException when trying to evaluate in fsharpi
Summary: System.TypeInitializationException + System.NullReferenceException when tryin...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 3.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-09-25 05:28 UTC by jmchapman+bugzilla
Modified: 2014-01-05 10:48 UTC (History)
4 users (show)

Tags:
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 GitHub or Developer Community 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:
RESOLVED FIXED

Description jmchapman+bugzilla 2013-09-25 05:28:59 UTC
tested with 3.2.3 and 3.2.1_1

// If I make my own version of the option type like this:

type MyOption<'t> =
  | MySome of 't
  | MyNone

// I can use construct an element of it that contains an int:

> MySome 1;;
val it : MyOption<int> = MySome 1

// but if try with a string then this happens:

> MySome "hello";;
System.TypeInitializationException: An exception was thrown by the type initializer for MyOption`1 ---> System.NullReferenceException: Object reference not set to an instance of an object
  at FSI_0006+MyOption`1[System.String]..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at <StartupCode$FSI_0009>.$FSI_0009.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

// If I try to use None it also causes an exception:

> MyNone;;
System.TypeInitializationException: An exception was thrown by the type initializer for MyOption`1 ---> System.NullReferenceException: Object reference not set to an instance of an object
  at FSI_0006+MyOption`1[System.Object]..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at <StartupCode$FSI_0007>.$FSI_0007.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

// If I use a let then I get slightly different results:

// MyNone now works:

> let x = MyNone;;

val x : MyOption<'a>

// MySome 1 words as before:

> let x = MySome 1;;

val x : MyOption<int> = MySome 1

> let x = MySome "string";;

// MySome "string" still doesn't work:

let x = MySome "string";;
System.TypeInitializationException: An exception was thrown by the type initializer for MyOption`1 ---> System.NullReferenceException: Object reference not set to an instance of an object
  at FSI_0006+MyOption`1[System.String]..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at <StartupCode$FSI_0009>.$FSI_0009.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 Zoltan Varga 2014-01-05 10:48:50 UTC
Fixed in mono master 9921b0306faf2fd308e6a62922e5a4ce85f6ade2.