microsoft/aspire · error · InvalidOperationException

The configuration file

Error message

The configuration file '{0}' contains invalid JSON: {1}

What it means

ConfigurationService.LoadSettingsFileForReading parses a settings file's content with JsonNode.Parse and, on JsonException, rethrows as an InvalidOperationException with the same 'invalid JSON' message including the file path and parser detail. Unlike AspireConfigFile.Load this is the settings-file reader path, used when reading global/project config values.

Solutions

  1. Fix the JSON syntax in the file at the reported path/position
  2. Validate with `jq . <file>` or a JSON linter before retrying the CLI command
  3. Restore the file from version control or delete it to regenerate defaults
  4. Check for tools or scripts that may be writing partial/invalid content concurrently

Example fix

// before
{ "features": { "disabled": true,, }
// after
{ "features": { "disabled": true } }
Defensive patterns

Strategy: validation

Validate before calling

try { JsonNode.Parse(File.ReadAllText(settingsPath), documentOptions: ConfigurationHelper.ParseOptions); }
catch (JsonException ex) { Console.Error.WriteLine($"{settingsPath} is invalid JSON: {ex.Message}"); }

Try / catch

try { var settings = await configService.LoadSettingsForReadingAsync(path); }
catch (InvalidOperationException ex) when (ex.InnerException is JsonException jex)
{ Console.Error.WriteLine($"Fix {path}: {jex.Message}"); return 1; }

Prevention

When it happens

Trigger: Reading a global or project settings/config file whose content is not valid JSON — e.g. corrupted aspire.config.json or a settings file edited by hand or another tool with a syntax error.

Common situations: Concurrent writers truncating the file, manual edits with syntax errors, or shell redirection appending invalid content to the config file.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/b770164f10a2fc70. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Cli/Configuration/ConfigurationService.cs:478

        }
        catch (UnauthorizedAccessException)
        {
            return new ConfigurationBuilder().Build();
        }

        if (string.IsNullOrWhiteSpace(content))
        {
            return new ConfigurationBuilder().Build();
        }

        JsonNode? node;
        try
        {
            node = JsonNode.Parse(content, documentOptions: ConfigurationHelper.ParseOptions);
        }
        catch (JsonException ex)
        {
            throw new InvalidOperationException(
                string.Format(CultureInfo.CurrentCulture, ErrorStrings.InvalidJsonInConfigFile, filePath, ex.Message),
                ex);
        }

        if (node is not JsonObject)
        {
            return new ConfigurationBuilder().Build();
        }

        var cleanJson = node.ToJsonString();
        var bytes = System.Text.Encoding.UTF8.GetBytes(cleanJson);
        return new ConfigurationBuilder()
            .AddJsonStream(new MemoryStream(bytes))
            .Build();
    }
}

View on GitHub (pinned to 25830f84bd)