PC Review


Reply
Thread Tools Rate Thread

Catching ConfigurationException when the config file is corrupted

 
 
Atara
Guest
Posts: n/a
 
      15th Mar 2005
My application starts with:

Module mmcMain
Public Sub Main()
Debug.WriteLine("Main begin")

Dim splashForm As New mcDlgs.cmcDlgSplash2
splashForm.Show()
....

Accidently I corrapted my config file (missing quote sign -> not valid
xml file) and I got unHandled Exception. Since my real users might also
do the same, I decided to handle this exception.

The information I had is:
An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: The '"' character, hexadecimal value 0x22,
cannot be included in a name. Line 82, position 34.

Call Stack:

system.dll!System.Configuration.ConfigurationSettings.SetConfigurationSy
stem(System.Configuration.IConfigurationSystem configSystem) + 0x74
bytes

system.dll!System.Configuration.ConfigurationSettings.GetConfig(string
sectionName) + 0x80 bytes

system.dll!System.Diagnostics.DiagnosticsConfiguration.GetConfigTable()
+ 0xe bytes
system.dll!System.Diagnostics.DiagnosticsConfiguration.Initialize()
+ 0x80 bytes

system.dll!System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
+ 0x7 bytes
system.dll!System.Diagnostics.TraceInternal.InitializeSettings() +
0x34 bytes
system.dll!System.Diagnostics.TraceInternal.get_Listeners() + 0x1b
bytes
system.dll!System.Diagnostics.TraceInternal.WriteLine(string
message) + 0x35 bytes
system.dll!System.Diagnostics.Debug.WriteLine(string message) + 0x6
bytes
> mc2.exe!Synergix.mc.mmcMain.Main() Line 13 + 0xc bytes Basic


so I added some code at the begginning of my Main():

Module mmcMain
Public Sub Main()

Try
Dim testStr As String =
System.Configuration.ConfigurationSettings.AppSettings("testStr")
Catch ex1 As System.Configuration.ConfigurationException
Dim strTitle As String = "MC2 Configuration Exception"
Dim strText As String = "Default values will be used." &
ControlChars.NewLine & ex1.ToString()
ShowMyDialog(strTitle, strText)
Catch ex As Exception
Dim strTitle As String = "other Exception"
Dim strText As String = ex.ToString()
ShowMyDialog(strTitle, strText)
End Try

' Debug.WriteLine("Main begin")

Dim splashForm As New mcDlgs.cmcDlgSplash2
splashForm.Show()
....


At the beginning I commented out the 'Debug.WriteLine' line to get all
my application functions that should catch the ConfigurationException,
but now, even if I do not comment out the "Debug" line, it does not
throw any exceptions.

To sum-up:

1) If I comment out the 'Try' block - the "Debug" throws exception. I
can understand that though there should be a simple way to handle it.
(How about .Net internal error handler "config file is corrupted" ???)

2) If I have the 'Try' block - the "Debug" does not throw exception,
(and I can see its output in the output window). Though the "Debug" line
is outside the Try block. Can you explain why does not it throw
exception?

3) Do you have any other ideas to handle the exceptions of corrupted
config file?

Thanks
Atara.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Atara
Guest
Posts: n/a
 
      22nd Mar 2005
Anyone ?

Am I the only one that accidetly corrupted my config file?

How do you handle such situation in the real world were users that are
not familiar with xml have to change your well-formed .config files?

Thanks.
Atara




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I restore a corrupted user.config file? Jeremy Chaney Microsoft C# .NET 3 9th May 2007 12:53 AM
Corrupted c:\winnt\system32\config\system file Edward Diener Microsoft Windows 2000 4 4th Sep 2005 04:12 AM
Corrupted c:\winnt\system32\config\system file Edward Diener Microsoft Windows 2000 Setup 2 18th Mar 2005 02:22 AM
corrupted system32/config/system file jennifer Windows XP Performance 2 11th Nov 2003 07:07 PM
XP ..\config\system file corrupted, can't boot XP BryanB Windows XP Help 2 17th Oct 2003 06:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.