Windows Service 'System.Typeinitializationexception' on startup

Asked

Viewed 701 times

2

Hello,

I am creating a windows service to perform a backup job. I have created other services before but never had a similar problem.

Everything was going well, during the development I installed the service on a computer and was running it normally to do the tests and adjustments, just before finishing the work the service stopped running, whenever it started it showed the following message in the eventvwr:

Application: Backup67.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled Exception. Exception Info: System.Typeinitializationexception Stack: at Winservice.WinService.Main()

And right after this:

Faulting application name: Backup67.exe, version: 0.0.0.0,

time Stamp: 0x552c2561

Faulting module name: KERNELBASE.dll, version: 6.1.7601.18229,

time Stamp: 0x51fb1116 Exception code: 0xe0434352

Fault offset: 0x0000c41f

Faulting process id: 0x2bec

Faulting application start time: 0x01d07627884c559e

Faulting application path: C: Backup67.exe

Faulting module path: C: Windows syswow64 KERNELBASE.dll

Report Id: c5fb41de-e21a-11e4-a82f-001e67aaf90c

I found strange and tried to run the process on my machine by F5 of visual studio, the same error appeared:

An unhandled Exception of type 'System.Typeinitializationexception' occurred in Unknown Module.

Additional information: The type initializer of 'Winservice.Winservice' triggered an exception.

I’ve been trying to debug, but I can’t, because apparently the system doesn’t even run the service, it gets stopped before it can enter any breakpoint or catch I can place. I have tried to use Appdomain for the Unhandledexceptions but also unsuccessfully.

I’ve been looking for a solution ever since, tried to change the framework, change the CPU type, but none of it worked. What I’m finding strange is that the program was working until just before the error, perfectly, there was no change in the system, I just changed the name of a variable and this error appeared.

Anyone who can help, I’d be grateful. Att,

  • To InnerException by Visual Studio does not give more details?

  • I can’t get the Innerexception... No matter where I put Try/catch it never falls on the block.

  • You some static constructor in the service?

  • I have the Main method, which is static, but the constructor of the class is not static.

1 answer

1


Turns out the problem was a static variable. There was a definition that pointed to another class and then he was giving a Nullpointerexception.

Following this link in solution number 5, the user said to go to the menu DEBUG->Exceptions and mark all checkboxes to display all possible exceptions, by doing this the system pointed me exactly where was the error in the static variable. I just removed the reference to another class and everything worked normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.