0

I've installed Mono and tried to run my .NET application on Linux.

This is what I get:

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

I don't get this error on Windows so I can't use the VS debugger.

I tried adding a try..catch() and Console.WriteLine the inner exception, but my application crashes anyways. The code looks like:

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

I also start another thread before, but my program stops crashing if I comment the line above.

And the method itself:

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

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

I'm very confused and I'm trying to figure the issue for over an hour with no luck. Help would be great!

shavit
  • 842
  • 1
  • 7
  • 17
  • More or less a duplicate of http://stackoverflow.com/questions/12425199/type-initialization-exception. You exception is not caused by the method, but the static constructor on type that contains `Method`, which is `Class`. – kiziu Nov 20 '16 at 01:32
  • @kiziu yes, apparently it couldn't find one of the types I had there from an external assembly. How unfortunate.. – shavit Nov 21 '16 at 00:13

1 Answers1

0

I solved it by moving the initializers to a method, then I got the real exception behind System.TypeInitializationException!

shavit
  • 842
  • 1
  • 7
  • 17