{"record":{"id":"1184b18c8444e0ee","repo":"microsoft/semantic-kernel","slug":"could-not-determine-the-assembly-path","errorCode":null,"errorMessage":"Could not determine the assembly path.","messagePattern":"Could not determine the assembly path\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithProcesses/Utilities/MermaidRenderer.cs","lineNumber":50,"sourceCode":"        {\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();\n        browserFetcher.Browser = SupportedBrowser.Chrome;\n        await browserFetcher.DownloadAsync();\n\n        // Define the HTML template with Mermaid.js CDN\n        string htmlContent = $@\"\n        <html>\n            <head>\n                <style>\n                    body {{","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithProcesses/Utilities/MermaidRenderer.cs#L32-L68","documentation":"Thrown in the relative-path branch when Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) returns null. This indicates the assembly has no file location (e.g. loaded from a single-file publish bundle, in-memory, or a dynamic assembly), so the renderer cannot derive a base output folder.","triggerScenarios":"Calling GenerateMermaidImageAsync with a relative filename when the executing assembly's Location is empty (single-file app, in-memory load, AppContext.BaseDirectory-only host).","commonSituations":"Publishing as a single-file executable; running tests where the assembly is loaded in-memory; container/scenarios where Location is not set.","solutions":["Pass an absolute path so the relative branch is skipped entirely.","Use AppContext.BaseDirectory instead of Assembly.Location in caller setup, and pass an absolute path built from it."],"exampleFix":"// before\nawait MermaidRenderer.GenerateMermaidImageAsync(code, \"diagram.png\"); // fails under single-file publish\n// after\nstring abs = Path.Combine(AppContext.BaseDirectory, \"output\", \"diagram.png\");\nawait MermaidRenderer.GenerateMermaidImageAsync(code, abs);","handlingStrategy":"validation","validationCode":"string baseDir = !string.IsNullOrEmpty(Assembly.GetExecutingAssembly().Location)\n    ? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!\n    : AppContext.BaseDirectory;\nstring abs = Path.Combine(baseDir, \"output\", filename);\nawait MermaidRenderer.GenerateMermaidImageAsync(code, abs);","typeGuard":"bool HasAssemblyLocation() => !string.IsNullOrEmpty(Assembly.GetExecutingAssembly().Location);","tryCatchPattern":"try { await MermaidRenderer.GenerateMermaidImageAsync(code, filename); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"assembly path\")) { /* pass an absolute path built from AppContext.BaseDirectory */ }","preventionTips":["Under single-file publish, prefer AppContext.BaseDirectory over Assembly.Location.","Pass absolute output paths to avoid the assembly-derived relative branch.","Test rendering under single-file deployment in CI."],"tags":["mermaid","filesystem","assembly","single-file","deployment"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}