{"record":{"id":"acc142fe18185d2c","repo":"microsoft/semantic-kernel","slug":"could-not-determine-the-directory-path","errorCode":null,"errorMessage":"Could not determine the directory path.","messagePattern":"Could not determine the directory path\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithProcesses/Utilities/MermaidRenderer.cs","lineNumber":38,"sourceCode":"    public static async Task<string> GenerateMermaidImageAsync(string mermaidCode, string filenameOrPath)\n    {\n        // Ensure the filename has the correct .png extension\n        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        }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithProcesses/Utilities/MermaidRenderer.cs#L20-L56","documentation":"Thrown when Path.GetDirectoryName(outputFilePath) returns null for a rooted input. GetDirectoryName returns null only for paths like '/' or a bare root, meaning no directory component could be resolved. The renderer needs a concrete directory to validate/create.","triggerScenarios":"Calling GenerateMermaidImageAsync with an absolute path whose directory component is null, e.g. '/foo.png' on some platforms yields a directory, but a root-only path like '/' or a malformed path yields null.","commonSituations":"Passing a bare root path, an empty directory, or a path constructed incorrectly so GetDirectoryName returns null.","solutions":["Supply an absolute path that has a real parent directory, e.g. '/tmp/out/diagram.png'.","Prepend a working directory when only a filename is needed: use a relative path so the assembly-directory branch is taken.","Validate the path resolves to a non-root directory before calling."],"exampleFix":"// before\nawait MermaidRenderer.GenerateMermaidImageAsync(code, \"/diagram.png\");\n// after\nstring dir = Path.Combine(Path.GetTempPath(), \"mermaid\");\nDirectory.CreateDirectory(dir);\nawait MermaidRenderer.GenerateMermaidImageAsync(code, Path.Combine(dir, \"diagram.png\"));","handlingStrategy":"validation","validationCode":"string? dir = Path.GetDirectoryName(Path.GetFullPath(filename));\nif (string.IsNullOrEmpty(dir) || dir == Path.GetPathRoot(dir))\n    throw new ArgumentException(\"Provide a path with a real parent directory.\", nameof(filename));","typeGuard":"bool HasRealDirectory(string p) { var d = Path.GetDirectoryName(Path.GetFullPath(p)); return !string.IsNullOrEmpty(d) && d != Path.GetPathRoot(d); }","tryCatchPattern":"try { await MermaidRenderer.GenerateMermaidImageAsync(code, filename); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"directory path\")) { /* rebuild path with a concrete dir */ }","preventionTips":["Always combine a concrete base directory with the filename.","Avoid root-only paths when constructing output locations.","Use Path.GetFullPath to validate resolved paths early."],"tags":["mermaid","filesystem","path","argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}