从F#——Mono.Debugger.Soft.VMDisconnectedException调用C#

从F#——Mono.Debugger.Soft.VMDisconnectedException调用C#,c#,f#,mono,C#,F#,Mono,任何人都可以从f代码调用c函数 我有这样一个c#函数 public class VehicleDetailsBridge { public void SaveVehicle(long id) { var db = "test call"; } } 那么在f#中,我有: 我在我的F#项目中有一个C#类库的参考 但是,当我运行此代码时,在Xamarin中会出现以下异常: Mono.Debugger.Soft.VMDisconnectedExecptio

任何人都可以从f代码调用c函数

我有这样一个c#函数

public class VehicleDetailsBridge
{

    public void SaveVehicle(long id)
    {
         var db = "test call";
     }
}
那么在f#中,我有:

我在我的F#项目中有一个C#类库的参考

但是,当我运行此代码时,在Xamarin中会出现以下异常:

Mono.Debugger.Soft.VMDisconnectedExecption

试试这个:

let b = VehicleDetailsBridge() // create instance of class
b.SaveVehicle(LatestVid)
VehicleDetailsBridge是一个类,因此您需要将其作为类打开

type Persistence() =                         // need braces here, and not 'as this'
    member x.SaveToDatabase(latestVid) =
        let b = VehicleDetailsBridge()       // indent the method body
        b.SaveVehicle(latestVid)
我的完整F#计划如下:

open FsCsInterop

type Persistence() =                         // need braces here, and not 'as this'
    member x.SaveToDatabase(latestVid) =
        let b = VehicleDetailsBridge()       // indent the method body
        b.SaveVehicle(latestVid)
        printfn "Saved %d" latestVid

[<EntryPoint>]
let main argv = 
    let p = Persistence()
    p.SaveToDatabase(2L)
    0

// Prints "Saved 2"
打开FsCsInterop
键入Persistence()=//此处需要大括号,而不是“像这样”
成员x.SaveToDatabase(最新视频)=
设b=VehicleDetailsBridge()//缩进方法体
b、 保存车辆(最新视频)
打印fn“已保存%d”最新视频
[]
让主argv=
设p=Persistence()
p、 SaveToDatabase(2L)
0
//打印“已保存2”

目前仍然存在相同的错误,尝试实例化时是否可以引用c#from f#breaking?我无法重现您的问题,我现在在家,在Mac上的Xamarin上试用过,效果很好。鉴于Patrick McDonald提供的正确语法,我无法在Windows上的Visual Studio中重现此问题。。。我建立了一个C#library项目,并从F#console项目中引用了它,并从
Main
调用了
persistence
类。没问题。很容易得出结论,这个问题与特定的Mono环境有关。。。
open FsCsInterop

type Persistence() =                         // need braces here, and not 'as this'
    member x.SaveToDatabase(latestVid) =
        let b = VehicleDetailsBridge()       // indent the method body
        b.SaveVehicle(latestVid)
        printfn "Saved %d" latestVid

[<EntryPoint>]
let main argv = 
    let p = Persistence()
    p.SaveToDatabase(2L)
    0

// Prints "Saved 2"