2

我用 C# 编写了一个程序。它使用 F# 映射。

该程序运行良好,没有错误。但是,当我尝试使用以下内容对其进行分析时:

mono --profile=log:report Program.exe

我收到以下错误:

[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Object is not a Bar 
 at Test.Bar.CompareTo (System.Object obj) [0x00000] in <filename unknown>:0 
 at 
 Microsoft.FSharp.Core.LanguagePrimitives+HashCompare.GenericCompare$cont@923-1       
(Microsoft.FSharp.Core.GenericComparer comp, System.Object yobj, System.Object xobj,   
IComparable x, Microsoft.FSharp.Core.Unit unitVar) [0x00000] in <filename unknown>:0 
at Microsoft.FSharp.Core.LanguagePrimitives+HashCompare.GenericCompare 
(Microsoft.FSharp.Core.GenericComparer comp, System.Object xobj, System.Object yobj)
[0x00000] in <filename unknown>:0 
at 
Microsoft.FSharp.Core.LanguagePrimitives
+HashCompare.GenericComparisonWithComparerIntrinsic[Bar] 
(IComparer comp, Test.Bar x, Test.Bar y) [0x00000] in <filename unknown>:0
at   
Microsoft.FSharp.Core.LanguagePrimitives+HashCompare.GenericComparisonIntrinsic[Bar]
(Test.Bar x, Test.Bar y) [0x00000] in <filename unknown>:0 
at Microsoft.FSharp.Core.LanguagePrimitives+-cctor@2099-1[Test.Bar].Compare 
(Test.Bar   x, Test.Bar y) [0x00000] in <filename unknown>:0 
at Microsoft.FSharp.Collections.MapTreeModule.add[Bar,Foo] (IComparer`1
comparer, Test.Bar k, Test.Foo v, Microsoft.FSharp.Collections.MapTree`2
m) [0x00000] in <filename unknown>:0 
at Microsoft.FSharp.Collections.MapTreeModule.mkFromEnumerator[Bar,Foo] 
(IComparer`1 comparer, Microsoft.FSharp.Collections.MapTree`2 acc, IEnumerator`1 e)
[0x00000] in <filename unknown>:0 
at Microsoft.FSharp.Collections.MapTreeModule.ofSeq[Bar,Foo] (IComparer`1   
comparer, IEnumerable`1 c) [0x00000] in <filename unknown>:0 
at Microsoft.FSharp.Collections.FSharpMap`2[Test.Bar,Test.Foo]..ctor 
(IEnumerable`1 elements) [0x00000] in <filename unknown>:0 

似乎只有当我使用探查器运行程序时,才会调用类 Bar 的方法 CompareTo(object obj),而某些东西似乎不是 Bar。

该方法通过以下方式实现:

public int CompareTo(object obj) 
{
    if (obj == null) return 1;

    Bar otherBar = obj as Bar;
    if (otherBar != null) 
        return this.CompareTo(otherBar);
    else
        throw new ArgumentException("Object is not a Bar!");
}       

如上所述,如果没有分析,则不会发生此错误。

mono --version 给出:

Mono JIT compiler version 2.10.5 (Debian 2.10.5-1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
       TLS:           __thread
       SIGSEGV:       altstack
       Notifications: epoll
       Architecture:  x86
       Disabled:      none
       Misc:          softdebug 
       LLVM:          supported, not enabled.
       GC:            Included Boehm (with typed GC and Parallel Mark)

更新:

mono --profile=log:sample Program.exe
mono --profile=log:nocalls Program.exe

两者都有效。但是,我也想让标准分析器工作。

这是 Mono 中的错误,还是我做错了什么?

4

1 回答 1

1

根据跨平台包的 F# 官方页面,您应该使用 Mono 2.10.9 或更高版本。

所以先尝试升级单声道。

于 2012-08-07T16:00:50.663 回答