473,395 Members | 1,541 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,395 software developers and data experts.

Catching Application Configuration Error...

Is there a way to catch an application configuration error on startup?

I have written a windows service. If there is an error in the configuration
file (such as invalid xml) the exception is thrown before the OnStart method
is invoked. Is there a way to catch this exception?

Thank you,

Jason Richmeier
Jul 9 '08 #1
4 1734
Hi Jason,

No, errors in the configuration files are thrown by .Net Framework before
the application is loaded. If this is a common issue, consider using a
separate configuration file and load it manually.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Jason Richmeier" wrote:
Is there a way to catch an application configuration error on startup?

I have written a windows service. If there is an error in the configuration
file (such as invalid xml) the exception is thrown before the OnStart method
is invoked. Is there a way to catch this exception?

Thank you,

Jason Richmeier
Jul 9 '08 #2
Actually, configuration errors are thrown when the configuration is first
accessed, not when the appdomain is being loaded. If your service is
throwing an exception before OnStart is called you might want look at your
code and make sure you aren't accessing the ConfigurationManager somewhere
that would cause it to get thrown before the service has started.

The service is created in your Program.cs file (assuming you're using Visual
Studio), I'd start looking in there first. Also check your service class for
any static variables or class variables that are being set as the class is
being instantiated.

"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:BE**********************************@microsof t.com...
Hi Jason,

No, errors in the configuration files are thrown by .Net Framework before
the application is loaded. If this is a common issue, consider using a
separate configuration file and load it manually.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Jason Richmeier" wrote:
>Is there a way to catch an application configuration error on startup?

I have written a windows service. If there is an error in the
configuration
file (such as invalid xml) the exception is thrown before the OnStart
method
is invoked. Is there a way to catch this exception?

Thank you,

Jason Richmeier
Jul 9 '08 #3
Well, since the configuration files may contain sections meant for the CLR
describing how the application is to be run, the configuration file is read
prior to running any application code.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Jeff Winn" wrote:
Actually, configuration errors are thrown when the configuration is first
accessed, not when the appdomain is being loaded. If your service is
throwing an exception before OnStart is called you might want look at your
code and make sure you aren't accessing the ConfigurationManager somewhere
that would cause it to get thrown before the service has started.

The service is created in your Program.cs file (assuming you're using Visual
Studio), I'd start looking in there first. Also check your service class for
any static variables or class variables that are being set as the class is
being instantiated.

"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:BE**********************************@microsof t.com...
Hi Jason,

No, errors in the configuration files are thrown by .Net Framework before
the application is loaded. If this is a common issue, consider using a
separate configuration file and load it manually.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Jason Richmeier" wrote:
Is there a way to catch an application configuration error on startup?

I have written a windows service. If there is an error in the
configuration
file (such as invalid xml) the exception is thrown before the OnStart
method
is invoked. Is there a way to catch this exception?

Thank you,

Jason Richmeier
Jul 10 '08 #4
I had pretty much come to this conclusion. I wasn't sure if there was
anything that I could put in the Startup class (where Main is located) to
trap the error. I do like the idea you presented. My configuration file has
a custom configuration section so I have to manually load this section anyway.

Thank you,

Jason Richmeier

"Morten Wennevik [C# MVP]" wrote:
Well, since the configuration files may contain sections meant for the CLR
describing how the application is to be run, the configuration file is read
prior to running any application code.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Jeff Winn" wrote:
Actually, configuration errors are thrown when the configuration is first
accessed, not when the appdomain is being loaded. If your service is
throwing an exception before OnStart is called you might want look at your
code and make sure you aren't accessing the ConfigurationManager somewhere
that would cause it to get thrown before the service has started.

The service is created in your Program.cs file (assuming you're using Visual
Studio), I'd start looking in there first. Also check your service class for
any static variables or class variables that are being set as the class is
being instantiated.

"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:BE**********************************@microsof t.com...
Hi Jason,
>
No, errors in the configuration files are thrown by .Net Framework before
the application is loaded. If this is a common issue, consider using a
separate configuration file and load it manually.
>
--
Happy Coding!
Morten Wennevik [C# MVP]
>
>
"Jason Richmeier" wrote:
>
>Is there a way to catch an application configuration error on startup?
>>
>I have written a windows service. If there is an error in the
>configuration
>file (such as invalid xml) the exception is thrown before the OnStart
>method
>is invoked. Is there a way to catch this exception?
>>
>Thank you,
>>
>Jason Richmeier
Jul 10 '08 #5

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

Similar topics

7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
6
by: Javier Cortés Cortés | last post by:
i am getting this error when i am trying to access any file(with the ext. aspx) from my remote server. the error is : Server Error in '/' Application....
3
by: Damian | last post by:
Hi everyone I'm having an issue with one of our applications. I'm getting the following error when attempting to log in to the site: Server Error in 'xxxxxxxxxxxxxxxx' Application....
4
by: tommy | last post by:
hello everbody, i write a little asp-application with forms-authentication. i copy my aspx-files with web.config to my webspace and i get the error above... i tried to set the...
9
by: Wayne Wengert | last post by:
I built an ASP application and it runs fine on my local IIS. I am trying to move the application to my web service (ISP) out on the internet. I've read several of the help articles but they all...
3
by: Sean | last post by:
HI There, I am having trouble deploying my .aspx pages to a remote server, I have made changes to the config file and it still returns an error. I have also contacted the server administrator to...
12
by: Kevin Farless | last post by:
Hi all, I'm having trouble viewing any .aspx pages on my hosting company's server. The server is a new box running Windows Server 2003 default installation. I'm the first client to try using...
2
by: Chris_24 | last post by:
To all, I am experiencing difficulties with an asp.net web application and its web.config file. No matter what I try I keep getting the following error: Server Error in '/action' Application....
1
by: Atara | last post by:
My application starts with: Module mmcMain Public Sub Main() Debug.WriteLine("Main begin") Dim splashForm As New mcDlgs.cmcDlgSplash2 splashForm.Show() ....
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.