473,396 Members | 2,017 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,396 software developers and data experts.

How do I restore a corrupted user.config file?

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
Feb 13 '07 #1
3 10456
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(Configur ationUserLevel.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
May 7 '07 #2
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();
}

May 8 '07 #3
"aa**********@gmail.com" 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?
May 9 '07 #4

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

Similar topics

2
by: Mark | last post by:
Our team uses VSS. We each have a user.config file for local settings. One developer's file does NOT kick in - it pulls directly from the web.config file. 1. The user.config file is in the...
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: Nenad Dobrilovic | last post by:
Hi all, I have a really strange situation, but I believe that there is someone else who has already experinced the same, and is willing to help me! I made an application using VS 2005 in C#,...
1
by: Jeremy Chaney | last post by:
It appears that my user.config file got corrupted causing my "InitializeComponent" routine to throw an exception "Root element is missing." when I start my app. I figure I can just go into...
3
by: DaBrain | last post by:
I have a program that uses settings. When I save my settings they are saved: Properties.Settings.Default.Save(); when I restart the application, my settings are present, the changes are in...
1
by: Robert Dufour | last post by:
Changing a setting in the UserSettings from within my app using code (Vs2005 vb.net) does not seem to persist changes to the myapp.exe.config file what is the location and name of the file where...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
3
by: Piotrekk | last post by:
Hi I have a problem connected with user.config file. I am using default settings.settings . To settings.settings I am adding one user scope string and one application scope string. Thus...
1
by: =?Utf-8?B?QXNobGV5VA==?= | last post by:
I am using the .config and My.Settings to get my connection string. I need it to first look in some directory specific for the logged in user. If it isn't there then look to the program...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.