如何在Linux上调试TypeInitializationException?

时间:2016-11-19 22:12:29

标签: c# mono

我已经安装了Mono,并尝试在Linux上运行我的.NET应用程序。

这就是我得到的:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'namespace.Class' threw an exception.
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00017] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00031] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'shave.ChatBot' threw an exception.
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00017] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00031] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0

没有在Windows上出现此错误,因此我无法使用VS调试器。

我尝试添加try..catch()Console.WriteLine内部异常,但我的应用程序仍会崩溃。代码如下:

new Thread(Class.Method).Start();

我之前也开始了另一个帖子,但是如果我评论上面的行,我的程序就会停止崩溃。

方法本身:

public static async void Method()
{
    Console.WriteLine($"{Prefix.Info} Connecting.");

    await /* my async connection method here */;
}

我非常困惑,我试图在没有运气的情况下解决这个问题超过一个小时。帮助会很棒!

1 个答案:

答案 0 :(得分:0)

我通过将初始化器移动到方法来解决它,然后我在{{1}}后面得到了真正的异常!