microsoft/aspire · error · InvalidOperationException

The configuration file mount could not be parsed.

Error message

The configuration file mount could not be parsed.

What it means

RunAsEmulator builds the emulator's Config.json by parsing generated JSON with JsonNode.Parse; if the parse yields null the mount content is invalid and the extension throws InvalidOperationException rather than mounting a broken config file into the container.

Solutions

  1. Review each ConfigJsonAnnotation / config-modify callback and validate the JSON it produces (e.g. round-trip through JsonNode) before it is applied
  2. Log or print the final config string and parse it locally to find the syntax error
  3. Remove config customizations one at a time to isolate which callback breaks parsing

Example fix

// before
.WithConfigJsonModify(cfg => { /* wrote malformed JSON */ })
// after
.WithConfigJsonModify(cfg =>
{
    cfg["Configuration"]["MaxReplicationMessageSizeBytes"] = 1048576; // mutate the parsed node, not raw text
});
Defensive patterns

Strategy: validation

Validate before calling

_ = JsonNode.Parse(finalConfigJson) ?? throw new InvalidOperationException("Generated emulator config is not valid JSON");

Try / catch

try { builder.RunAsEmulator(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("configuration file mount")) { /* inspect config-modify callbacks */ }

Prevention

When it happens

Trigger: JsonNode.Parse returning null for the generated default config or for content composed with ConfigJsonAnnotation modifications — practically a defensive check hit when customization produced an unparseable/empty document.

Common situations: A ConfigJsonAnnotation callback replacing content with an empty string or invalid JSON; a bug in custom JSON patching code passed to RunAsEmulator's WithConfigJsonModify.

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/9a3dd15de411f640. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.cs:334

            {
                var customConfigFile = builder.Resource.Annotations.OfType<ConfigFileAnnotation>().FirstOrDefault();
                if (customConfigFile != null)
                {
                    return Task.FromResult<IEnumerable<ContainerFileSystemItem>>([
                        new ContainerFile
                        {
                            Name = AzureEventHubsEmulatorResource.EmulatorConfigJsonFile,
                            SourcePath = customConfigFile.SourcePath,
                        },
                    ]);
                }

                // Create default Config.json file content
                var tempConfig = JsonNode.Parse(CreateEmulatorConfigJson(builder.Resource));

                if (tempConfig == null)
                {
                    throw new InvalidOperationException("The configuration file mount could not be parsed.");
                }

                // Apply ConfigJsonAnnotation modifications
                var configJsonAnnotations = builder.Resource.Annotations.OfType<ConfigJsonAnnotation>();

                if (configJsonAnnotations.Any())
                {
                    foreach (var annotation in configJsonAnnotations)
                    {
                        annotation.Configure(tempConfig);
                    }
                }

                using var writeStream = new MemoryStream();
                using var writer = new Utf8JsonWriter(writeStream, new JsonWriterOptions { Indented = true });
                tempConfig.WriteTo(writer);

                writer.Flush();

View on GitHub (pinned to 25830f84bd)