asynchronous - 定位 Microsoft.FSharp.Control.Trampoline 抛出的异常

标签 asynchronous f#

我负责 F# WPF 应用程序 .当发生未处理的异常时,它会向我发送电子邮件。大多数情况下,我能够从错误消息和堆栈跟踪中确定异常的来源。但是,我偶尔会收到如下消息,其中不包含堆栈跟踪中的任何代码。

Summary:
Object reference not set to an instance of an object.
--------------
Details:

System.NullReferenceException: 
Object reference not set to an instance of an object.
   at Microsoft.FSharp.Control.CancellationTokenOps.Start@1234-1.Invoke(Exception e)
   at <StartupCode$FSharp-Core>.$Control.loop@435-40(Trampoline this, FSharpFunc`2 action)
   at Microsoft.FSharp.Control.Trampoline.ExecuteAction(FSharpFunc`2 firstAction)
   at Microsoft.FSharp.Control.TrampolineHolder.Protect(FSharpFunc`2 firstAction)
   at <StartupCode$FSharp-Core>.$Control.-ctor@520-1.Invoke(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

此堆栈跟踪中有哪些可用线索可以帮助我确定此异常的来源?

例如,我假设原始异常是在 async 中抛出的。计算。 (我的大部分异步代码基于 F# 异步块。)我的 NullReferenceException 可以吗?发生在 async 中的任何地方堵塞?我注意到异常发生在 Start() 中方法。或者是吗?那个Start()方法需要一个 Exception实例所以可能在此之前抛出异常。这能告诉我什么吗?我想知道是否有人对 Microsoft.FSharp.Control.Trampoline 足够熟悉为我指明正确的方向。

顺便说一下,在我的错误处理代码中,我很小心地检查了所有 InnerExceptions和处理 AggregateExceptions .所以我认为这是 Exception 实例中可用的所有信息,但我可能是错的。

最佳答案

我做了一个快速测试。以下控制台程序生成相同的堆栈跟踪。

[<EntryPoint>]
let main argv = 

    async { printfn "Inside async block."
            let o = null
            o.GetType() |> ignore
    } |> Async.Start

    System.Console.ReadKey(true) |> ignore
    0 // return an integer exit code

这告诉我以下内容:
  • 神秘异常发生在异步块中。
  • 它可能发生在异步块中的任何地方。
  • 诊断的唯一方法是改进异步块周围的错误处理(可能使用 Async.Catch)并重新部署应用程序的新版本并等待它再次发生。
  • 关于asynchronous - 定位 Microsoft.FSharp.Control.Trampoline 抛出的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35369199/

    相关文章:

    c# - 响应式扩展 - 属性相互更新

    performance - Tornado AsyncHTTPClient 请求在中等负载下超时

    c# - 是否有像 f# 中那样的通用拆箱功能?

    f# - 多个数据成员属性

    casting - 在 F# 中将 DateTime 分配给 Nullable<DateTime>

    asynchronous - Dart 中事件循环何时启动以及事件队列如何工作

    java - JBoss 6 中的异步处理 ("Comet")

    javascript - Mongoose 的 findOneAndUpdate 和 upsert 中的重复键错误

    C# 到 F# CRC16 ^ 和 ^^^ 的工作方式不同。 ^ 如何运作?

    带有 <"string"的 F# 构造函数,str>