dziemborowicz / hourglass

The simple countdown timer for Windows.
MIT License
631 stars 112 forks source link

Settings become corrupt (ConfigurationErrorsException) #243

Open dziemborowicz opened 1 year ago

dziemborowicz commented 1 year ago

There are numerous reports of the following error on startup sometimes:

System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: '.', hexadecimal value 0x00, is an invalid character. Line 9, position 1. (C:\Users\[Redacted]\AppData\Local\Chris_Dziemborowicz\Hourglass.exe_Url_la3v0chg0cfk1mkapgxkzi2xaouqgqcm\1.15.0.0\user.config line 9) ---> System.Xml.XmlException: '.', hexadecimal value 0x00, is an invalid character. Line 9, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
   at System.Xml.XmlTextReaderImpl.ParseText()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Configuration.XmlUtil.StrictReadToNextElement(ExceptionAction action)
   at System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(XmlUtil xmlUtil, String parentConfigKey, Boolean inLocation, String locationSubPath, OverrideModeSetting overrideMode, Boolean skipInChildApps)
   at System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(XmlUtil xmlUtil, String parentConfigKey, Boolean inLocation, String locationSubPath, OverrideModeSetting overrideMode, Boolean skipInChildApps)
   at System.Configuration.BaseConfigurationRecord.ScanSections(XmlUtil xmlUtil)
   at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
   --- End of inner exception stack trace ---
   at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
   at System.Configuration.Internal.InternalConfigRoot.OnConfigRemoved(InternalConfigEventArgs e)
   at System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(String configPath, BaseConfigurationRecord configRecord)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
   at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
   at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
   at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
   at System.Configuration.SettingsBase.get_Item(String propertyName)
   at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
   at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
   at Hourglass.Properties.Settings.get_UpgradeRequired()
   at Hourglass.Managers.SettingsManager.Initialize()
   at Hourglass.Managers.AppManager.Initialize()
   at Hourglass.AppEntry.OnStartup(StartupEventArgs e)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at Hourglass.AppEntry.Main(String[] args)
The error has been written to "C:\Users\[Redacted]\AppData\Local\Temp\Hourglass-Crash.20230526-140529-2061082.txt".

In one case, the data in the settings file looked like this:

Screenshot

I would presume this happens if the app doesn't finish writing out the data while it's shutting down, or something like that.

Potential solutions:

  1. Backup the old copy before starting to save updated settings (and restore old settings on failure).
  2. Write out settings as soon as something changes, instead of on app shutdown. It's less likely the app will be killed during settings save in that case. And less likely that changes will be unsaved in general.
amigo993 commented 10 months ago

Hi there, I'm just a user of this app, getting the same error on startup, could you please clarify the workaround a bit: where to find the settings and what do you mean by "write out settings"? Can I fix the corrupted settings file if I haven't made any backups before?

dziemborowicz commented 10 months ago

This happens when the settings file has become corrupted. The settings file isn't deleted when you uninstall or reinstall the app, but you can delete it yourself by deleting the following folder:

C:\Users\<your_username>\AppData\Local\Chris_Dziemborowicz\Hourglass.exe_Url_<some_random_characters>

For example, it might look like --

C:\Users\amigo993\AppData\Local\Chris_Dziemborowicz\Hourglass.exe_Url_la3v0chg0cfk1mkapgxkzi2xaouqgqcm

This means that, unfortunately, any settings you may have customized will be reset, but hopefully the app will work again.

Let me know if that doesn't work.

amigo993 commented 10 months ago

@dziemborowicz, it worked, thank you!