Walkingsteak
Walkingsteak

Reputation: 349

Properties.Settings.Default value is null after changing it, and calling Save() and Reload()

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

Upvotes: 0

Views: 1390

Answers (1)

Luaan
Luaan

Reputation: 63772

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.

Upvotes: 1

Related Questions