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

When RunAsEmulator builds the emulator's Config.json, it parses the generated JSON with JsonNode.Parse and throws InvalidOperationException if the result is null (i.e. the string represented only JSON null or whitespace). This is an internal invariant: CreateEmulatorConfigJson should always produce a parseable object, so a null parse means the mount content could not be produced.

Solutions

  1. Update Aspire.Hosting.Azure.ServiceBus to the latest version, since this indicates the generated config template is broken.
  2. Check whether any WithConfigJson-like annotations or custom code altered the configuration pipeline and remove the interference.
  3. Rebuild/clean your AppHost and re-restore packages to repair a corrupted install.
  4. If reproducible, file an issue with the AppHost code that triggers it — this exception is not expected in normal use.

Example fix

// before (suspected custom mutation corrupting config)
sb.RunAsEmulator(e => e.WithConfigJson("null"));
// after
sb.RunAsEmulator(e => e.WithConfigJson(configBuilder => { /* valid JSON object */ }));
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    sb.RunAsEmulator();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("configuration file mount could not be parsed"))
{
    // remove custom config mutations / WithConfigJson annotations, or update package, then retry
}

Prevention

When it happens

Trigger: Calling RunAsEmulator when JsonNode.Parse(CreateEmulatorConfigJson(builder.Resource)) returns null — the generated default config string is effectively empty or the literal null.

Common situations: Modified or broken custom config generation (e.g. extensions/hooks that overwrite the config source); corrupted package install where the template content is missing; very rare framework bug.

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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs:484

            {
                var customConfigFile = builder.Resource.Annotations.OfType<ConfigFileAnnotation>().FirstOrDefault();
                if (customConfigFile != null)
                {
                    return Task.FromResult<IEnumerable<ContainerFileSystemItem>>([
                        new ContainerFile
                        {
                            Name = AzureServiceBusEmulatorResource.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)