DefaultSettingValueAttribute Class

Specifies the default value for an application settings property.

Namespace: System.Configuration
Assembly: System (in system.dll)

public sealed class DefaultSettingValueAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property) */ 
public final class DefaultSettingValueAttribute extends Attribute
public final class DefaultSettingValueAttribute extends Attribute
Not applicable.


DefaultSettingValueAttribute can only be applied to individual settings properties; it is invalid to apply this attribute to an entire application settings class.

Different settings providers may have different requirements or limitations on the use of the DefaultSettingValueAttribute. For example, the LocalFileSettingsProvider does not require this attribute, and will override any value provided by this attribute if there are any values—default or user-modified— already present in the data store.

DefaultSettingValueAttribute requires that the default value can be represented as a string. As a result, settings using XML serialization cannot have a default value specified by means of this attribute. Some providers may choose to support multiple serialization schemes which can be specified at compile time using the SettingsSerializeAsAttribute.

Caution noteCaution:

The default values specified by this attribute are stored as plain text in the resultant compiled .exe or .dll file. Therefore these default values are inherently insecure.

The following code example demonstrates the use of the DefaultSettingValueAttribute applied to three of the four properties of the FormSettings wrapper class, which is derived from the ApplicationSettingsBase class. This class is used to persist the location, size, background color, and text of form. The first three of these form properties have default values associated with them.

The full code example is listed in the ApplicationSettingsBase class overview.

//Application settings wrapper class
sealed class FormSettings : ApplicationSettingsBase
    public String FormText
        get { return (String)this["FormText"]; }
        set { this["FormText"] = value; }

    [DefaultSettingValueAttribute("0, 0")]
    public Point FormLocation
        get { return (Point)(this["FormLocation"]); }
        set { this["FormLocation"] = value; }

    [DefaultSettingValueAttribute("225, 200")]
    public Size FormSize
        get { return (Size)this["FormSize"]; }
        set { this["FormSize"] = value; }

    public Color FormBackColor
        get { return (Color)this["FormBackColor"]; }
        set { this["FormBackColor"] = value; }



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions