I have my program which has some Application Settings and some User Settings. On some machines my User Settings config file becomes corrupt and stops my program loading. I then log into the machine and delete the UserConfig directory stored at
%USERPROFILE%\Appdata\Local\MyApp
When my file is corrupt the error thrown is Configuration Settings Failed To Initialize
so I was wondering if this happened in my program whether there was a way to delete the corrupt file and reset the configuration.
So far I have:
try
{
var prop1= Settings.Default.prop1;
}
catch (Exception ex)
{
var userSettingsLocation =
Path.Combine(Environment.ExpandEnvironmentVariables(
"%USERPROFILE%"), "AppData","Local", "MyApp");
if (Directory.Exists(userSettingsLocation))
{
DeleteDirectory(userSettingsLocation); // This is a reccursive
// delete method
// I need to reload settings
}
}
This deletes the file fine but if I try to read my settings again using for example: Settings.Reset();
I still get the same error. I need to somehow reset the configuration Settings after deleting the corrupt file. Is this possible?