tui-cs/Terminal.Gui · error · JsonException

Error Applying Configuration Change: {tie.InnerException.Mes

Error message

Error Applying Configuration Change: {tie.InnerException.Message}

What it means

Thrown by ConfigProperty.Apply when PropertyInfo.SetValue (invoking a static [ConfigurationProperty] setter) raises a TargetInvocationException that carries an InnerException. The inner message is surfaced. This means the config value deserialized fine but the target property's setter rejected it at runtime (e.g. a value-out-of-range, invalid enum, or domain rule).

Source

Thrown at Terminal.Gui/Configuration/ConfigProperty.cs:93

    public bool Apply ()
    {
        try
        {
            if (PropertyInfo?.GetValue (null) is { })
            {
                // Use DeepCloner to create a deep copy of PropertyValue
                object? val = DeepCloner.DeepClone (PropertyValue);

                Debug.Assert (!Immutable);
                PropertyInfo.SetValue (null, val);

            }
        }
        catch (TargetInvocationException tie)
        {
            if (tie.InnerException is { })
            {
                throw new JsonException (
                                         $"Error Applying Configuration Change: {tie.InnerException.Message}",
                                         tie.InnerException
                                        );
            }

            throw new JsonException ($"Error Applying Configuration Change: {tie.Message}", tie);
        }
        catch (ArgumentException ae)
        {
            throw new JsonException (
                                     $"Error Applying Configuration Change ({PropertyInfo?.Name}): {ae.Message}",
                                     ae
                                    );
        }

        return PropertyValue != null;
    }

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Read the InnerException message text — it names the real setter-level failure.
  2. Adjust the config value to satisfy the property's runtime contract.
  3. If the property is from a newer/older version, align the config with the library version in use.
  4. Set ConfigurationManager.ThrowOnJsonErrors = false to demote to a logged error during Apply (the offending property is skipped).
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate by setting the property directly in a dry-run before Apply.
try { propInfo.SetValue (null, testValue); }
catch (Exception e) { Log ($"Setter rejects value: {e.Message}"); }

Try / catch

try { ConfigurationManager.Apply (); }
catch (JsonException ex) when (ex.Message.StartsWith ("Error Applying Configuration Change"))
{
    var inner = ex.InnerException; // the real setter exception
    Log ($"Apply failed on a property: {inner?.Message}");
}

Prevention

When it happens

Trigger: A config value passes JSON parsing but violates a setter invariant — e.g. a numeric config property set to a negative value, an enum property set to an undefined member after a version change, or a readonly-after-init guard firing.

Common situations: Version skew: config written for an older Terminal.Gui where a property accepted a wider value range; a custom [ConfigurationProperty] the user added whose setter validates strictly; an environment where a global resource (e.g. screen) rejects the value.

Related errors


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