chamar funções F # de C # e recebendo exceções referência nula
Pergunta
Estou usando o Visual Studio 2008 com outubro 2009 F # CTP instalado.
Eu estou tentando chamar algum código F # do meu programa C #. A maioria dos tipos de funções F # parecem funcionar, mas alguns não estão sendo inicializado em F # e estão jogando NullReferenceExceptions. Os únicos a fazer isso são encerramentos e funções parcialmente aplicados, ou seja, coisas que aparecem no C # como FastFunc <> tipos.
Existe algo que eu estou fazendo de errado ou esquecer, ou este é possivelmente um erro com F # ou .NET?
o código abaixo é para demonstrar o problema. Eu não estou realmente tentando usar este código em uma aplicação real. também, dentro de F #, tudo funciona corretamente. este é um F # -a-C # problema
F #:
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 () -> "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) -> o.ToString() + i.ToString()
let ClosureWrapper (i:int) =
Closure i
C # (F referências projeto # e FSharp.Core)
//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
Solução
Ele funciona para mim, eu recebo "o que está acima Olá", "System.Object1", "System.Object1" para parcial, encerramento e closureWrapper Vars. Você está referenciando o bom FSharp.Core montagem?