PC Review


Reply
Thread Tools Rate Thread

How do I restore a corrupted user.config file?

 
 
Jeremy Chaney
Guest
Posts: n/a
 
      13th Feb 2007
It appears that my user.config file got corrupted causing my
"InitializeComponent" routine to throw the exception "Root element is
missing." when I start my app.

I figure I can just go into Explorer and delete the file to get things
working again, but I'd rather just catch the exception and resolve the
error programatically. I tried "Properties.Settings.Default.Reset();"
but that just throws the exception too. Does anyone know how I can
programatically get the user.config file back into a good state? The
path to the file looks like it is obfuscated (one of the folders in the
path contains the string "zc3rx3dim2uzbjjmpqetzf4h0qujaeb5"), so I don't
see trying to delete the file as a viable option.

Thanks,
--Jeremy
 
Reply With Quote
 
 
 
 
=?Utf-8?B?R3JhbnQgRnJpc2tlbg==?=
Guest
Posts: n/a
 
      7th May 2007
Hi Jeremy

Have you found any resolution to this issue? This seems to me to be a very
large flaw in the design of the application settings mechanism.

In my experience user settings files inevitably get corrupted at some stage
by users terminating application as it is writing the settings. You need to
have some ability to reset the settings in this instance. Unfortunately ,as
you noted, the path to the user.config file is somewhat cryptic. The
documented method of getting the path for the user.config file is to call:

Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
string path = config.FilePath;

However this also fails with an exception if the config file is corrupt.

--
Grant Frisken
Infralution
www.infralution.com


"Jeremy Chaney" wrote:

> It appears that my user.config file got corrupted causing my
> "InitializeComponent" routine to throw the exception "Root element is
> missing." when I start my app.
>
> I figure I can just go into Explorer and delete the file to get things
> working again, but I'd rather just catch the exception and resolve the
> error programatically. I tried "Properties.Settings.Default.Reset();"
> but that just throws the exception too. Does anyone know how I can
> programatically get the user.config file back into a good state? The
> path to the file looks like it is obfuscated (one of the folders in the
> path contains the string "zc3rx3dim2uzbjjmpqetzf4h0qujaeb5"), so I don't
> see trying to delete the file as a viable option.
>
> Thanks,
> --Jeremy
>

 
Reply With Quote
 
aaronsussman@gmail.com
Guest
Posts: n/a
 
      8th May 2007
On May 6, 8:21 pm, Grant Frisken
<GrantFris...@discussions.microsoft.com> wrote:
> Hi Jeremy
>
> Have you found any resolution to this issue? This seems to me to be a very
> large flaw in the design of the application settings mechanism.
>
> In my experience user settings files inevitably get corrupted at some stage
> by users terminating application as it is writing the settings. You need to
> have some ability to reset the settings in this instance. Unfortunately ,as
> you noted, the path to theuser.configfile is somewhat cryptic. The
> documented method of getting the path for theuser.configfile is to call:
>
> Configuration config =
> ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoa*mingAndLocal);
> string path = config.FilePath;
>
> However this also fails with an exception if the config file iscorrupt.
>
> --
> Grant Frisken
> Infralutionwww.infralution.com
>
>
>
> "Jeremy Chaney" wrote:
> > It appears that myuser.configfile got corrupted causing my
> > "InitializeComponent" routine to throw the exception "Root element is
> > missing." when I start my app.

>
> > I figure I can just go into Explorer and delete the file to get things
> > working again, but I'd rather just catch the exception and resolve the
> > error programatically. I tried "Properties.Settings.Default.Reset();"
> > but that just throws the exception too. Does anyone know how I can
> > programatically get theuser.configfile back into a good state? The
> > path to the file looks like it is obfuscated (one of the folders in the
> > path contains the string "zc3rx3dim2uzbjjmpqetzf4h0qujaeb5"), so I don't
> > see trying to delete the file as a viable option.

>
> > Thanks,
> > --Jeremy- Hide quoted text -

>
> - Show quoted text -


catch the ConfiguarationErrorsException. Somethign like this.



catch (System.Configuration.ConfigurationErrorsException ex)
{
string fileName = "";
if (!string.IsNullOrEmpty(ex.Filename))
{
fileName = ex.Filename;
}
else
{

System.Configuration.ConfigurationErrorsException innerException =
ex.InnerException as
System.Configuration.ConfigurationErrorsException;
if (innerException != null && !
string.IsNullOrEmpty(innerException.Filename))
{
fileName = innerException.Filename;
}
}
if (System.IO.File.Exists(fileName))
{
System.IO.File.Delete(fileName);
}
UpgradeSettings();
}

 
Reply With Quote
 
=?Utf-8?B?R3JhbnQgRnJpc2tlbg==?=
Guest
Posts: n/a
 
      9th May 2007
"(E-Mail Removed)" wrote:
>
> catch the ConfiguarationErrorsException. Somethign like this.
>
> catch (System.Configuration.ConfigurationErrorsException ex)
> {
> string fileName = "";
> if (!string.IsNullOrEmpty(ex.Filename))
> {
> fileName = ex.Filename;
> }
> else
> {
>
> System.Configuration.ConfigurationErrorsException innerException =
> ex.InnerException as
> System.Configuration.ConfigurationErrorsException;
> if (innerException != null && !
> string.IsNullOrEmpty(innerException.Filename))
> {
> fileName = innerException.Filename;
> }
> }
> if (System.IO.File.Exists(fileName))
> {
> System.IO.File.Delete(fileName);
> }
> UpgradeSettings();
> }
>


Thanks - that gets me part way there. What does your UpgradeSettings
method do? I tried calling Upgrade, Reset and Reload on the
Properties.Settings.Default object after deleting the file. The first two
fail with the same exception. Reload doesn't fail - however if you try to
access a setting property after this it still fails. Does this mean that
the only option if this error occurs is to force the user to exit and restart?
 
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
Corrupted c:\winnt\system32\config\system file Edward Diener Microsoft Windows 2000 4 4th Sep 2005 04:12 AM
Catching ConfigurationException when the config file is corrupted Atara Microsoft VB .NET 1 22nd Mar 2005 09:38 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 11:36 PM.