On May 6, 8:21 pm, Grant Frisken
<GrantFris...@discussions.microsoft.comwrote:
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(Configur ationUserLevel.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();
}