【问题标题】:How does one debug TypeInitializationException on Linux?如何在 Linux 上调试 TypeInitializationException?
【发布时间】:2016-11-19 22:12:29
【问题描述】:

我已经安装了 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 */;
}

我很困惑,我试图解决这个问题一个多小时,但没有运气。帮助会很棒!

【问题讨论】:

  • 或多或少是stackoverflow.com/questions/12425199/… 的副本。你的异常不是由方法引起的,而是包含Method的类型的静态构造函数,即Class
  • @kiziu 是的,显然它找不到我从外部程序集中拥有的类型之一。多么不幸..

标签: c# mono


【解决方案1】:

我通过将初始化程序移动到一个方法来解决它,然后我得到了System.TypeInitializationException背后的真正异常!

【讨论】:

    猜你喜欢
    • 2013-10-27
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2011-01-06
    • 2010-09-19
    • 2020-08-19
    相关资源
    最近更新 更多