473,385 Members | 2,044 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,385 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 2055

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.