Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winforms .Net Application won't start

Tags:

c#

.net

winforms

I have a standard winforms application that runs on most machines. On a 2003 server with .Net 4 (full) installed it doesn't run.

The event viewer shows:

Event Type: Error
Event Source:   .NET Runtime
Event Category: None
Event ID:   1026
Date:       4/01/2012
Time:       10:07:37 AM
User:       N/A
Computer:   DRACO
Description:
Application: start.exe
Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.
Exception 
Info: System.TypeInitializationException
Stack:
   at BootStrap.Program.Main(System.String[])

Event Type: Error
Event Source:   .NET Runtime 4.0 Error Reporting
Event Category: None
Event ID:   1000
Date:       4/01/2012
Time:       10:07:34 AM
User:       N/A
Computer:   DRACO
Description:
Faulting application start.exe, version 1.0.4386.17553, stamp 4f0384f3, faulting module     kernel32.dll, version 5.2.3790.4480, stamp 49c51f0a, debug? 0, fault address 0x0000bef7.

It fails on the Main() call so I can't trap the errors. How do I tell what the problem is?

like image 418
P Hemans Avatar asked Dec 04 '22 18:12

P Hemans


2 Answers

The exception is a TypeInitializationException. This is thrown when an exception was generated executing the initializer code for a type. Basically the static constructor or the initialization of static fields. Some part of that initialization is throwing an exception which results in a TypeInitializationException

The exception information itself will say which type is causing this via the TypeName property.

It's hard to say for certain what is causing this problem. The quickest way to find out would be to start the process under a debugger and set it to break on any thrown exception. That should immediately lead you to the root cause.

like image 110
JaredPar Avatar answered Dec 25 '22 14:12

JaredPar


The interesting part is the following: System.TypeInitializationException

This means that one of the types used in your main method failed to initialize. Usually the static constructor is throwing an exception which is caught by the initializer and then re-thrown as inner exception of a System.TypeInitializationException. Catch the exception in your main method and show its inner exception or use a debugger.

like image 37
Muepe Avatar answered Dec 25 '22 15:12

Muepe