I am using the Settings-file in my project to store application settings. The problem I ran into:
Properties.Settings.Default.IpAddress = IPAddress.Parse("192.168.0.1");
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
var ipaddress = Properties.Settings.Default.IpAddress;
here, ipaddress
ends up with a null
value. If I inspect Properties.Settings.Default.IpAddress
before Reload()
is called, it has the correct value.
Properties.Settings.Default.IpAddress is set to User as Scope
As per the documentation, for a type to be useable in application settings, it must either be Xml serializable, or have a TypeConverter
to and from string
. IPAddress
has neither, so it cannot be used in application settings.
You can use string
to store your IP address instead, or if that isn't convenient, make your own type that can handle the conversion properly.