473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I restore a corrupted user.config file?

It appears that my user.config file got corrupted causing my
"InitializeComp onent" 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.Set tings.Default.R eset();"
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 "zc3rx3dim2uzbj jmpqetzf4h0quja eb5"), so I don't
see trying to delete the file as a viable option.

Thanks,
--Jeremy
Feb 13 '07 #1
3 10499
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 =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.PerUserRoa mingAndLocal);
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
"InitializeComp onent" 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.Set tings.Default.R eset();"
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 "zc3rx3dim2uzbj jmpqetzf4h0quja eb5"), 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...@d iscussions.micr osoft.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.configf ile is somewhat cryptic. The
documented method of getting the path for theuser.configf ile is to call:

Configuration config =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.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.configfi le got corrupted causing my
"InitializeComp onent" 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.Set tings.Default.R eset();"
but that just throws the exception too. Does anyone know how I can
programatically get theuser.configf ile 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 "zc3rx3dim2uzbj jmpqetzf4h0quja eb5"), so I don't
see trying to delete the file as a viable option.
Thanks,
--Jeremy- Hide quoted text -

- Show quoted text -
catch the ConfiguarationE rrorsException. Somethign like this.

catch (System.Configu ration.Configur ationErrorsExce ption ex)
{
string fileName = "";
if (!string.IsNull OrEmpty(ex.File name))
{
fileName = ex.Filename;
}
else
{

System.Configur ation.Configura tionErrorsExcep tion innerException =
ex.InnerExcepti on as
System.Configur ation.Configura tionErrorsExcep tion;
if (innerException != null && !
string.IsNullOr Empty(innerExce ption.Filename) )
{
fileName = innerException. Filename;
}
}
if (System.IO.File .Exists(fileNam e))
{
System.IO.File. Delete(fileName );
}
UpgradeSettings ();
}

May 8 '07 #3
"aa**********@g mail.com" wrote:
>
catch the ConfiguarationE rrorsException. Somethign like this.

catch (System.Configu ration.Configur ationErrorsExce ption ex)
{
string fileName = "";
if (!string.IsNull OrEmpty(ex.File name))
{
fileName = ex.Filename;
}
else
{

System.Configur ation.Configura tionErrorsExcep tion innerException =
ex.InnerExcepti on as
System.Configur ation.Configura tionErrorsExcep tion;
if (innerException != null && !
string.IsNullOr Empty(innerExce ption.Filename) )
{
fileName = innerException. Filename;
}
}
if (System.IO.File .Exists(fileNam e))
{
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.Sett ings.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
4780
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 same directory as the web.config (root). 2. There is nothing crazy about the contents. The contents are posted below. 3. The user.config file is in the appropriate directory, but has not been included in VSS.
1
3124
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
1221
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#, which uses one setting from *.exe.config file with 'user' scope. That is a server address, for example. I wanted to setup that parameter during installation. So, I included one additonal step during installation which collects a server address...
1
4407
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 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...
3
11643
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 fact saved. All is good! However, When I go to the application Folder application.exe.config and open the file, the file has my original design time settings for
1
8589
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 the usersettings are persisted? Is there any way to have modifications made in code to application level settings? The my.settings in VS2005 and vb.net 2005 does not permit application level settings to be modified in code cause the geniuses at MS...
5
7845
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 setting is of course stored in the app.exe.config file located in the same directory as the exe. Upon closing the form, I save the user setting which then creates a user.config file in the appdata directory in my profile. This is all well and good....
3
4059
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 app.config file is added to my project. When I build and run the project app.exe.config file is created and added to application base directory. This file contains two strings added previously. Q1: No user.config file is created in my documents and...
1
1057
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 installation folder for the .exe.config. Ideas on how to best do this. Thanks,
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.