【发布时间】: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 是的,显然它找不到我从外部程序集中拥有的类型之一。多么不幸..