{"record":{"id":"1b3d7f87a300ec6d","repo":"MahApps/MahApps.Metro","slug":"the-settings-file-filename-unknown-seem","errorCode":null,"errorMessage":"The settings file '{filename ?? \"<unknown>\"}' seems to be corrupted","messagePattern":"The settings file '(.+?)' seems to be corrupted","errorType":"exception","errorClass":"MahAppsException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/WindowSettings.cs","lineNumber":111,"sourceCode":"\n        [UserScopedSetting]\n        public WindowPlacementSetting? Placement\n        {\n            get\n            {\n                try\n                {\n                    return this[nameof(Placement)] as WindowPlacementSetting;\n                }\n                catch (ConfigurationErrorsException? ex)\n                {\n                    string? filename = null;\n                    while (ex != null && (filename = ex.Filename) == null)\n                    {\n                        ex = ex.InnerException as ConfigurationErrorsException;\n                    }\n\n                    throw new MahAppsException($\"The settings file '{filename ?? \"<unknown>\"}' seems to be corrupted\", ex);\n                }\n            }\n            set => this[nameof(Placement)] = value;\n        }\n\n        /// <summary>\n        /// Upgrades the application settings on loading.\n        /// </summary>\n        [UserScopedSetting]\n        public bool UpgradeSettings\n        {\n            get\n            {\n                try\n                {\n                    return (this[nameof(UpgradeSettings)] as bool?).GetValueOrDefault(true);\n                }\n                catch (ConfigurationErrorsException? ex)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/WindowSettings.cs#L93-L129","documentation":"Thrown by WindowSettings.Save()/load when deserializing the persisted WindowPlacement setting raises a ConfigurationErrorsException (e.g., the user.config or app settings file is malformed). The code walks the exception chain to find a filename and wraps it in a MahAppsException indicating corruption. The settings file stores window position/size across sessions.","triggerScenarios":"The user-scoped settings file (user.config) containing persisted WindowPlacement is corrupted—truncated, invalid XML, or schema-mismatched after a version change. The ConfigurationManager throws ConfigurationErrorsException during read, which is caught and rewrapped.","commonSituations":"App upgraded and the settings schema changed, leaving an incompatible user.config. Machine crashed or disk issue truncated the settings file. Roaming profile conflict writing partial data. First run after a settings property was renamed/removed.","solutions":["Delete the corrupted user.config file (typically under %LocalAppData%\\<Company\\<App\\<Version>\\user.config) and let the app recreate it.","Call ApplicationSettingsBase.Reset() or .Upgrade() after schema changes to migrate old settings.","Wrap the settings access in try-catch and fall back to default placement on ConfigurationErrorsException.","Ensure settings properties are only added, not renamed/removed, across versions—or implement ISettingsUpgrade."],"exampleFix":"// before\nvar placement = settings.Placement; // throws MahAppsException\n\n// after\nWindowPlacementSetting placement;\ntry\n{\n    placement = settings.Placement;\n}\ncatch (MahAppsException)\n{\n    // settings file corrupted: reset and use defaults\n    settings.Reset();\n    settings.Save();\n    placement = settings.Placement;\n}","handlingStrategy":"try-catch","validationCode":"// Before reading placement, check the settings file exists and is readable\nvar config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);\nif (!config.HasFile)\n    return null; // use default placement","typeGuard":null,"tryCatchPattern":"WindowPlacementSetting placement;\ntry\n{\n    placement = settings.Placement;\n}\ncatch (MahAppsException)\n{\n    settings.Reset();\n    settings.Save();\n    placement = settings.Placement;\n}","preventionTips":["Call settings.Reset() or settings.Upgrade() after schema changes to migrate old user.config files.","Wrap window-placement loading in try-catch and fall back to default placement.","On corruption, delete the user.config under %LocalAppData% and let the app recreate it.","Never rename or remove settings properties across versions without an upgrade plan."],"tags":["wpf","mahapps","settings","configuration","serialization","window-placement","corruption"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}