473,326 Members | 2,133 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,326 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 3576

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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.