tui-cs/Terminal.Gui · error · ArgumentException

OmitClassName is not allowed when Scope is AppSettingsScope

Error message

OmitClassName is not allowed when Scope is AppSettingsScope to ensure property names are globally unique.

What it means

Thrown by the ConfigurationPropertyAttribute.Scope setter: setting Scope to typeof(AppSettingsScope) while OmitClassName is true is rejected. AppSettingsScope keys must include the declaring class name to stay globally unique, so omitting it is forbidden. (Scope defaults to AppSettingsScope when unset, but the explicit-set path enforces the rule.)

Source

Thrown at Terminal.Gui/Configuration/ConfigurationPropertyAttribute.cs:35

    private Type? _scope;

    /// <summary>Specifies the scope of the property. If <see langword="null"/> then <see cref="AppSettingsScope"/> will be used.</summary>
    public Type? Scope
    {
        get
        {
            if (_scope is { })
            {
                return _scope;
            }
            return typeof (AppSettingsScope);
        }
        set
        {
            if (value == typeof (AppSettingsScope) && OmitClassName)
            {
                throw new ArgumentException ("OmitClassName is not allowed when Scope is AppSettingsScope to ensure property names are globally unique.");
            }
            _scope = value;
        }
    }
}

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Either set OmitClassName = false (default), so the key is ClassName.Property (globally unique),
  2. or change Scope to a non-AppSettings scope (e.g. a theme scope) where OmitClassName is permitted.
  3. Do not combine OmitClassName = true with Scope = typeof(AppSettingsScope).

Example fix

// before
[ConfigurationProperty (OmitClassName = true, Scope = typeof (AppSettingsScope))]
public static string? MyKey { get; set; }
// after
[ConfigurationProperty (Scope = typeof (AppSettingsScope))]
public static string? MyKey { get; set; }
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at attribute setup: never set both flags.
if (attr.OmitClassName && attr.Scope == typeof (AppSettingsScope))
    throw new ArgumentException ("OmitClassName cannot be true for AppSettingsScope.");

Type guard

static bool IsLegalAttributeCombo (ConfigurationPropertyAttribute a) =>
    !(a.OmitClassName && a.Scope == typeof (AppSettingsScope));

Try / catch

try { var a = new ConfigurationPropertyAttribute { OmitClassName = true, Scope = typeof (AppSettingsScope) }; }
catch (ArgumentException) { /* pick one: OmitClassName=false, or a different Scope */ }

Prevention

When it happens

Trigger: A property declared as [ConfigurationProperty(OmitClassName = true, Scope = typeof(AppSettingsScope))]. The combination is rejected at attribute construction / setter time.

Common situations: A developer wants a short key for an app-scoped property and sets both flags; copy-paste of a theme-scoped attribute pattern onto an app-scoped property.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/25b268df1a4f02db. Report an issue: GitHub.