Description
Description
In my console application I use the old-style Properties.Settings
concept. For now this implemented with help of the System.Configuration.ConfigurationManager
nuget package.
When I call Properties.Settings.Default.Upgrade();
on the newly created macOS user, I get the ArgumentNullException
with the following stacktrace
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at System.ArgumentException.ThrowNullOrEmptyException(String argument, String paramName)
at System.IO.Directory.GetParent(String path)
at System.Configuration.LocalFileSettingsProvider.GetPreviousConfigFileName(Boolean isRoaming)
at System.Configuration.LocalFileSettingsProvider.Upgrade(SettingsContext context, SettingsPropertyCollection properties, Boolean isRoaming)
at System.Configuration.LocalFileSettingsProvider.Upgrade(SettingsContext context, SettingsPropertyCollection properties)
at System.Configuration.ApplicationSettingsBase.Upgrade()
at Program.<Main>$(String[] args) in /Users/user/testUpgrade/Program.cs:line 15
zsh: abort
Reproduction Steps
- Download the test project test.zip
- Publish with
dotnet publish
- (!) Important: make sure that the following folders do NOT exist (they are really do not exist for the fresh newly created user)
~/.config/
~/.local/
- Run the published application directly ((!) do not use
dotnet run
, as it internally create settings folder before actually running the app) - Observe exception as described above (or, if the mentioned folder still exists, then you will see corresponding note and no crash)
Expected behavior
Application finished without exceptions.
Actual behavior
Unhandled ArgumentNullException
inside LocalFileSettingsProvider
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at System.ArgumentException.ThrowNullOrEmptyException(String argument, String paramName)
at System.IO.Directory.GetParent(String path)
at System.Configuration.LocalFileSettingsProvider.GetPreviousConfigFileName(Boolean isRoaming)
at System.Configuration.LocalFileSettingsProvider.Upgrade(SettingsContext context, SettingsPropertyCollection properties, Boolean isRoaming)
at System.Configuration.LocalFileSettingsProvider.Upgrade(SettingsContext context, SettingsPropertyCollection properties)
at System.Configuration.ApplicationSettingsBase.Upgrade()
at Program.<Main>$(String[] args) in /Users/user/testUpgrade/Program.cs:line 15
Regression?
The problem can be reproduced in net6/7.
Known Workarounds
No response
Configuration
- net versions I have tried: 6.0.408, 7.0.310, 8.0.101`
System.Configuration.ConfigurationManager
package versions: 6.0.1 and 8.0.0- macOS: 13.6.4 Ventura (x86) and 14.3.1 Sonoma (ARM64/Apple M2)
- Important: tested on newly created macos used, so no one has created settings folders yet.
Other information
When the ~/.local/
and ~/.config
folder are missing, the system can't build a path to the settings file, so
ConfigurationManager.OpenExeConfiguration(level).FilePath
gives null (or empty string) for the level = ConfigurationUserLevel.PerUserRoamingAndLocal
and level = ConfigurationUserLevel. PerUserRoaming
.
When executing Upgrade()
the ConfigurationManagerInternalFactory.Instance.ExeRoamingConfigDirectory
and ConfigurationManagerInternalFactory.Instance.ExeLocalConfigDirectory
are null here
And then we got exception in Directory.GetParent(null)
here