{"record":{"id":"9a3dd15de411f640","repo":"microsoft/aspire","slug":"the-configuration-file-mount-could-not-be-parsed","errorCode":null,"errorMessage":"The configuration file mount could not be parsed.","messagePattern":"The configuration file mount could not be parsed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.cs","lineNumber":334,"sourceCode":"            {\n                var customConfigFile = builder.Resource.Annotations.OfType<ConfigFileAnnotation>().FirstOrDefault();\n                if (customConfigFile != null)\n                {\n                    return Task.FromResult<IEnumerable<ContainerFileSystemItem>>([\n                        new ContainerFile\n                        {\n                            Name = AzureEventHubsEmulatorResource.EmulatorConfigJsonFile,\n                            SourcePath = customConfigFile.SourcePath,\n                        },\n                    ]);\n                }\n\n                // Create default Config.json file content\n                var tempConfig = JsonNode.Parse(CreateEmulatorConfigJson(builder.Resource));\n\n                if (tempConfig == null)\n                {\n                    throw new InvalidOperationException(\"The configuration file mount could not be parsed.\");\n                }\n\n                // Apply ConfigJsonAnnotation modifications\n                var configJsonAnnotations = builder.Resource.Annotations.OfType<ConfigJsonAnnotation>();\n\n                if (configJsonAnnotations.Any())\n                {\n                    foreach (var annotation in configJsonAnnotations)\n                    {\n                        annotation.Configure(tempConfig);\n                    }\n                }\n\n                using var writeStream = new MemoryStream();\n                using var writer = new Utf8JsonWriter(writeStream, new JsonWriterOptions { Indented = true });\n                tempConfig.WriteTo(writer);\n\n                writer.Flush();","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.cs#L316-L352","documentation":"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.","triggerScenarios":"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.","commonSituations":"A ConfigJsonAnnotation callback replacing content with an empty string or invalid JSON; a bug in custom JSON patching code passed to RunAsEmulator's WithConfigJsonModify.","solutions":["Review each ConfigJsonAnnotation / config-modify callback and validate the JSON it produces (e.g. round-trip through JsonNode) before it is applied","Log or print the final config string and parse it locally to find the syntax error","Remove config customizations one at a time to isolate which callback breaks parsing"],"exampleFix":"// before\n.WithConfigJsonModify(cfg => { /* wrote malformed JSON */ })\n// after\n.WithConfigJsonModify(cfg =>\n{\n    cfg[\"Configuration\"][\"MaxReplicationMessageSizeBytes\"] = 1048576; // mutate the parsed node, not raw text\n});","handlingStrategy":"validation","validationCode":"_ = JsonNode.Parse(finalConfigJson) ?? throw new InvalidOperationException(\"Generated emulator config is not valid JSON\");","typeGuard":null,"tryCatchPattern":"try { builder.RunAsEmulator(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"configuration file mount\")) { /* inspect config-modify callbacks */ }","preventionTips":["Modify the parsed JsonNode, never raw strings, in WithConfigJsonModify callbacks","Round-trip generated JSON through JsonNode.Parse before handing it to the resource","Test config-modify callbacks in unit tests"],"tags":["eventhubs","emulator","json","configuration"],"backgroundTag":"json-parse-error","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}