System.NullReferenceException在Xamarin上具有F和iOS

System.NullReferenceException在Xamarin上具有F和iOS,ios,f#,xamarin,Ios,F#,Xamarin,当执行一些测试代码测试托管在独立项目中但在Xamarin Studio中的同一解决方案中的不同模块时,我遇到了一个非常奇怪的错误 该解决方案承载2个项目。一个模块项目和一个测试项目。测试项目通过项目引用引用模块项目 //module-project/FluidLayout.fs namespace iosautolayout open System module Fluidity = type Init<'a> = Init of 'a type Right&

当执行一些测试代码测试托管在独立项目中但在Xamarin Studio中的同一解决方案中的不同模块时,我遇到了一个非常奇怪的错误

该解决方案承载2个项目。一个模块项目和一个测试项目。测试项目通过项目引用引用模块项目

//module-project/FluidLayout.fs
namespace iosautolayout
open System

 module Fluidity =
     type Init<'a> = Init of 'a
     type Right<'a> = Right of 'a
     type Left<'a> = Left of 'a

     type HorizontalBuilder() =
         member x.Yield(()) = Init "Init"
         [<CustomOperation("part")>]
         member x.Part(Init v, a) = Left "Left"

     let horizontal = new HorizontalBuilder()

      let create () = 
          let test_h = horizontal {
              part "test"
          }
          test_h
我完全不知道这里发生了什么


非常感谢您的帮助。

我找到了一个解决方案,但现在我更困惑了

如果我将“水平”更改为函数而不是val,则一切正常

namespace iosautolayout
open System

module Fluidity =
    type Init<'a> = Init of 'a
    type Right<'a> = Right of 'a
    type Left<'a> = Left of 'a

    type HorizontalBuilder() =
        member x.Yield(()) = Init "Init"
        [<CustomOperation("part")>]
        member x.Part(Init v, a) = Left "Left"

    let horizontal () = new HorizontalBuilder()
    let create () = 
        let test_h = horizontal() {
            part "test"
        }
        test_h
在交互式窗口中,使用水平作为值或函数并不重要

有人能解释一下这种行为吗

//test-project/AppDelegate.fs
namespace ioslibrarytests

open System
open MonoTouch.UIKit
open MonoTouch.Foundation
open MonoTouch.NUnit.UI

[<Register("AppDelegate")>]
type AppDelegate() = 
    inherit UIApplicationDelegate()
    override val Window = null with get, set
    override this.FinishedLaunching(app, options) = 
        this.Window <- new UIWindow(UIScreen.MainScreen.Bounds)
        let runner = new TouchRunner(this.Window)
        runner.Add (System.Reflection.Assembly.GetExecutingAssembly ());
        this.Window.RootViewController <- new UINavigationController (runner.GetViewController ());
        this.Window.MakeKeyAndVisible()
        true

module Main = 
    [<EntryPoint>]
    let main args = 
        UIApplication.Main(args, null, "AppDelegate")
        0
 2015-02-15 15:11:46.902 ioslibrarytests[1017:14804]    
 [FAIL] Create Structure with DSL : System.NullReferenceException : 
        Object reference not set to an instance of an object
 2015-02-15 15:11:46.902 ioslibrarytests[1017:14804] at
 iosautolayout.Fluidity.create () [0x00000] in 
 /Users/projekte/pawo-pic/ios-autolayout/FluidLayout.fs:17 
 2015-02-15 15:11:46.902 ioslibrarytests[1017:14804] at
 ioslibrarytests.Tests.Create Structure with DSL () [0x00000] in 
 /Users/projekte/pawo-pic/ios-library-tests/Tests.fs:17 
 2015-02-15 15:11:46.902 ioslibrarytests[1017:14804] at 
 (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke 
 (System.Reflection.MonoMethod,object,object[],System.Exception&)
 2015-02-15 15:11:46.902 ioslibrarytests[1017:14804] at 
 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags 
 invokeAttr,   System.Reflection.Binder binder, System.Object[] parameters, 
 System.Globalization.CultureInfo culture) [0x00044] in 
 /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:230 201
namespace iosautolayout
open System

module Fluidity =
    type Init<'a> = Init of 'a
    type Right<'a> = Right of 'a
    type Left<'a> = Left of 'a

    type HorizontalBuilder() =
        member x.Yield(()) = Init "Init"
        [<CustomOperation("part")>]
        member x.Part(Init v, a) = Left "Left"

    let horizontal () = new HorizontalBuilder()
    let create () = 
        let test_h = horizontal() {
            part "test"
        }
        test_h