Skip to content

.NET 9 breaks SaveWindowPosition #4541

@Suplanus

Description

@Suplanus

Describe the bug

If SaveWindowPosition = true in the MetroWindow and TargetFramework = net9.0-windows the application throws an exception on closing and not saving the window position:

ZH.TED.Test.WPF Error: 0 : MahApps.Metro.Behaviors.WindowsSettingBehavior: The settings could not be saved! System.Configuration.ConfigurationErrorsException: Failed to save settings: An error occurred loading a configuration file: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''.
 ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''.
 ---> System.InvalidOperationException: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''.
   at System.Configuration.ClientConfigurationHost.OpenStreamForWrite(String streamName, String templateStreamName, Object& writeContext)
   at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
   --- End of inner exception stack trace ---
   at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
   at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
   --- End of inner exception stack trace ---
   at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
   at System.Configuration.LocalFileSettingsProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
   at System.Configuration.SettingsBase.SaveCore()
   at System.Configuration.SettingsBase.Save()
   at MahApps.Metro.Behaviors.WindowsSettingBehavior.SaveWindowState()

Steps to reproduce

Here is an example project:
ZH.TED.Test.WPF.zip

If you switch to net8.0-windows as TargetFramework, it works as expected.

Environment

MahApps.Metro version: 2.4.10
Target Framework: .Net 9 (9.0.100)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions