This documentation is archived and is not being maintained.

DefaultSettingValueAttribute Class

Specifies the default value for an application settings property.

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

public sealed class DefaultSettingValueAttribute : Attribute

Important noteImportant Note:

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0