I have the following C# classes

public class BadClass { public BadClass(int? bad = 1) { } } public class GoodClass { public GoodClass(int? good = null) { } }

As you can see they both have optional nullable parameters as part of their constructors, the only difference is that BadClass has the parameter default set to something other than null.

If I attempt to create an instance of these classes in F# this is what I get:

This works fine:

let g = GoodClass()

This throws a NullReferenceException:

let b = BadClass()

And this throws an AccessViolationException

let asyncB = async { return BadClass() } |> Async.RunSynchronously

Any idea why this is?

EDIT

Using ILSpy to decompile it this is the output of the F#

The C# classes are in an assembly called InteopTest [sic]

ILSpy to C#

GoodClass g = new GoodClass(null); BadClass b = new BadClass(1); FSharpAsyncBuilder defaultAsyncBuilder = ExtraTopLevelOperators.DefaultAsyncBuilder; FSharpAsync<BadClass> fSharpAsync = defaultAsyncBuilder.Delay<BadClass>(new Program.asyncB@10(defaultAsyncBuilder)); FSharpAsync<BadClass> computation = fSharpAsync; BadClass asyncB = FSharpAsync.RunSynchronously<BadClass>(computation, null, null); FSharpFunc<string[], Unit> fSharpFunc = ExtraTopLevelOperators.PrintFormatLine<FSharpFunc<string[], Unit>>(new PrintfFormat<FSharpFunc<string[], Unit>, TextWriter, Unit, Unit, string[]>("%A")); fSharpFunc.Invoke(argv); return 0;

and this is the IL