title: calling F# functions from C# and getting null reference exceptions
body: <p>I'm using Visual Studio 2008 with the October 2009 F# CTP installed.</p>
  
  <p>I'm trying to call some F# code from my C# program.  Most types of F# functions seem to work, but some are not getting initialized in F# and are throwing NullReferenceExceptions.  The ones doing this are closures and partially applied functions, i.e. things that appear in C# as FastFunc&lt;> types.</p>
  
  <p>Is there something I'm doing wrong or forgetting, or is this possibly a bug with F# or .NET?</p>
  
  <p><em>the code below is to demo the problem. I'm not actually trying to use this code in a real application.</em>
  <em>also, within F#, everything works correctly. this is an F#-to-C# problem</em></p>
  
  <p>F#: </p>
  
  <pre><code>namespace FS      
  module FunctionTypes =
  
      //these all work in c# as expected
      let Value = "value"
  
      let OneParam (str:string) = str
  
      let TwoParam (str:string) (str2:string) = str + " " + str2
  
      let Lambda =
          fun () -&gt; "lambda"  
  
  
      //these functions are null references in C#
      // they do work as expected in F# interactive mode
      let PartialApplication = TwoParam "what's up"
  
      let Closure = 
          let o = new System.Object()
          fun (i:int) -&gt; o.ToString() + i.ToString()
  
      let ClosureWrapper (i:int) =
          Closure i  
  </code></pre>
  
  <p>C# (references F# project and FSharp.Core)</p>
  
  <pre><code> //these work as expected:
          var oneParam = FS.FunctionTypes.OneParam("hey");
          var twoParam = FS.FunctionTypes.TwoParam("yeah", "you");
          var lambdaFunction = FS.FunctionTypes.Lambda();
          var value = FS.FunctionTypes.Value;
          //  in the May09 CTP, Value returned null, 
          //      so it must have been fixed in Oct09 CTP
  
  
  
   //these do not work--each throws a NullReferenceException.
          var partial = FS.FunctionTypes.PartialApplication.Invoke("hello");
          var closure = FS.FunctionTypes.Closure.Invoke(1);
          var closureWrapper = FS.FunctionTypes.ClosureWrapper(1);
  
   //  FS.FunctionTypes.Closure itself is null, 
   //  so is FS.FunctionTypes.PartialAppliction.
   //  FS.FunctionTypes.ClosureWrapper is a regular function, 
   //    but it calls Closure, which is null     
  </code></pre>