473,288 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Error in Windows Service: The type initializer for "..." threw an exception

I'm writing my first windows service. I have a class called
'mainprocess' whose constructor is called by the service class.
Within mainprocess, I declare an instance of another class I wrote,
called DBHandler, which does all of my Sql Database work.

I have LogEvents everywhere and notice that the thread never gets
inside the DBHandler constructor. Instead, it throws this error as a
new instance of the DBHandler class is declared: 'Error in Windows
Service: The type initializer for "DBHandler" threw an exception'.

Here's where it's called in mainprocess:

public mainprocess()
{
init();
}

public void init()
{
try
{
string xmlfile = AppDomain.CurrentDomain.BaseDirectory +
"\\settings.xml";
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
xml.Load(xmlfile);
XmlElement element = xml.DocumentElement;
XmlNode node = element.SelectSingleNode("dbconnection[1]");
connectionstring = node.InnerText;
node = element.SelectSingleNode("picdirpath[1]");
picdir = node.InnerText;
node = element.SelectSingleNode("testbmp[1]");
testbmp = node.InnerText;
myLogger.LogEvent("Inside mainprocess.init(). DBHandler not yet
initialized.");
//WE CRASH AT THE NEXT LINE OF CODE!!!
myHandler = new DBHandler(connectionstring);
myLogger.LogEvent("Inside mainprocess.init(). DBHandler
initialized");
}
catch(Exception x)
{
myLogger.LogEvent("Error on init: " + x.Message);
}
}

Further, here is the constructor for DBHandler:
public DBHandler(string connection)
{
try
{
connectionstring = connection;
myLogger.LogEvent("Inside DBHandler. connection=" + connection);
myConnection.ConnectionString = connectionstring;
myLogger.LogEvent("Inside DBHandler.
myConnection.ConnectionString set");
}
catch(Exception e)
{
myLogger.LogEvent("Error in DBHandler constructor. " +
e.Message);
}
}
I know none of the constructor is being executed because nothing is
written to the event log.

The funny thing is, when I take the exact same code and wire it up to
a button click in an asp.net web app, it works fine. It just doesn't
work as a windows service. I'm at a loss.
Thanks,
Jon Gazsi
Nov 16 '05 #1
0 2091

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jinsu Park | last post by:
I am getting this error in the Server Explorer when I click on "Servers" icon: The type initializer for "System.Net.Dns" threw an exception. The type initializer for "System.Net.Sockets.Socket"...
0
by: Softer | last post by:
Hi I have been installed Longhorn, alfa version from PDC 2003. I tryed to install Visual Studio 8.0 "Whidbey", version Beta March 2004, under Longhorn and doesen't work. : I instaled Whidbey under...
2
by: Paul Gronka | last post by:
I've got a VB.NET windows application (written in VS .NET 2003) that makes a call to WMI for retrieving the MAC Address from the client's PC. It works on 4 out of the 5 PC's tested so far. All...
0
by: Jonathan G. | last post by:
I'm writing my first windows service. I have a class called 'mainprocess' whose constructor is called by the service class. Within mainprocess, I declare an instance of another class I wrote,...
0
by: Sam Fields | last post by:
I have found very little regarding the error "Unable to find an entry point named EnumerateSecurityPackagesW in DLL security.dll. ". I have an ASP.NET Web Service being accessed via SSL. I found...
4
by: MSNews | last post by:
I get the following exception when calling Dns.GetHostName (from C#): An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll Additional information: An...
1
by: ibiza | last post by:
Hi all, I have this class: Public Class KanaConverter Private Shared kana As ArrayList Private Shared romanji As ArrayList Shared Sub New() kana = New ArrayList
0
by: Rod | last post by:
I've got Crystal Reports XI Release 2, for development with Visual Studio ..NET 2005. I've taken a VS .NET 2003 WinForms application that I wrote in C#, and upgraded it to VS .NET 2005. It has...
2
by: RvGrah | last post by:
My program is giving a strange exception at startup, only on client machines. Runs fine on development machine. The app was upgraded long ago from a 2003 version to a VS2005 version, but continued...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.