{"record":{"id":"ccf32ab743718d4f","repo":"microsoft/semantic-kernel","slug":"the-directory-directorypath-does-not-exist","errorCode":null,"errorMessage":"The directory '{directoryPath}' does not exist.","messagePattern":"The directory '(.+?)' does not exist\\.","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithProcesses/Utilities/MermaidRenderer.cs","lineNumber":41,"sourceCode":"        if (!filenameOrPath.EndsWith(\".png\", StringComparison.OrdinalIgnoreCase))\n        {\n            throw new ArgumentException(\"The filename must have a .png extension.\", nameof(filenameOrPath));\n        }\n\n        string outputFilePath;\n\n        // Check if the user provided an absolute path\n        if (Path.IsPathRooted(filenameOrPath))\n        {\n            // Use the provided absolute path\n            outputFilePath = filenameOrPath;\n\n            // Ensure the directory exists\n            string directoryPath = Path.GetDirectoryName(outputFilePath)\n                ?? throw new InvalidOperationException(\"Could not determine the directory path.\");\n            if (!Directory.Exists(directoryPath))\n            {\n                throw new DirectoryNotFoundException($\"The directory '{directoryPath}' does not exist.\");\n            }\n        }\n        else\n        {\n            // Use the assembly's directory for relative paths\n            string? assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);\n            if (assemblyPath == null)\n            {\n                throw new InvalidOperationException(\"Could not determine the assembly path.\");\n            }\n\n            string outputPath = Path.Combine(assemblyPath, \"output\");\n            Directory.CreateDirectory(outputPath); // Ensure output directory exists\n            outputFilePath = Path.Combine(outputPath, filenameOrPath);\n        }\n\n        // Download Chromium if it hasn't been installed yet\n        BrowserFetcher browserFetcher = new();","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithProcesses/Utilities/MermaidRenderer.cs#L23-L59","documentation":"A DirectoryNotFoundException thrown when the absolute path provided to GenerateMermaidImageAsync points into a directory that does not exist on disk. The renderer refuses to write into a missing directory rather than silently creating it for absolute paths.","triggerScenarios":"Calling GenerateMermaidImageAsync with an absolute path whose parent directory has not been created (e.g. '/output/x.png' where /output is absent).","commonSituations":"Hard-coded output folder that was never created; running in an environment where the expected output directory differs; CI sandbox lacking the path.","solutions":["Create the target directory before calling: Directory.CreateDirectory(Path.GetDirectoryName(path)).","Use a relative filename so the renderer's assembly 'output' folder branch (which auto-creates) is used.","Point to a known-existing directory such as Path.GetTempPath()."],"exampleFix":"// before\nawait MermaidRenderer.GenerateMermaidImageAsync(code, @\"C:\\out\\diagram.png\"); // C:\\out missing\n// after\nstring dir = @\"C:\\out\"; Directory.CreateDirectory(dir);\nawait MermaidRenderer.GenerateMermaidImageAsync(code, Path.Combine(dir, \"diagram.png\"));","handlingStrategy":"validation","validationCode":"string dir = Path.GetDirectoryName(Path.GetFullPath(filename))!;\nDirectory.CreateDirectory(dir);\nawait MermaidRenderer.GenerateMermaidImageAsync(code, filename);","typeGuard":"bool DirectoryExistsFor(string p) { var d = Path.GetDirectoryName(Path.GetFullPath(p)); return d is not null && Directory.Exists(d); }","tryCatchPattern":"try { await MermaidRenderer.GenerateMermaidImageAsync(code, filename); }\ncatch (DirectoryNotFoundException) { Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(filename))!); /* retry */ }","preventionTips":["Pre-create output directories before writing.","Use Path.GetTempPath() as a known-good base.","Prefer relative filenames to use the renderer's auto-created output folder."],"tags":["mermaid","filesystem","directory","argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}