{"record":{"id":"bb8f74a8f7bdd5b4","repo":"microsoft/autogen","slug":"could-not-find-directory-for-assembly-asm","errorCode":null,"errorMessage":"Could not find directory for assembly '{asm}'.","messagePattern":"Could not find directory for assembly '(.+?)'\\.","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/dev-team/seed-memory/Program.cs","lineNumber":39,"sourceCode":"                .AddDebug();\n        });\n\n        var memoryBuilder = new MemoryBuilder();\n        var memory = memoryBuilder.WithLoggerFactory(loggerFactory)\n                    .WithQdrantMemoryStore(kernelSettings.QdrantEndpoint, 1536)\n                    .WithAzureOpenAITextEmbeddingGeneration(kernelSettings.EmbeddingDeploymentOrModelId, kernelSettings.Endpoint, kernelSettings.ApiKey)\n                    .Build();\n\n        await ImportDocumentAsync(memory, WafFileName).ConfigureAwait(false);\n    }\n\n    public static async Task ImportDocumentAsync(ISemanticTextMemory memory, string filename)\n    {\n        var asm = Assembly.GetExecutingAssembly();\n        var currentDirectory = Path.GetDirectoryName(asm.Location);\n        if (currentDirectory is null)\n        {\n            throw new DirectoryNotFoundException($\"Could not find directory for assembly '{asm}'.\");\n        }\n\n        var filePath = Path.Combine(currentDirectory, filename);\n        using var pdfDocument = PdfDocument.Open(File.OpenRead(filePath));\n        var pages = pdfDocument.GetPages();\n        foreach (var page in pages)\n        {\n            try\n            {\n                var text = ContentOrderTextExtractor.GetText(page);\n                var descr = text.Take(100);\n                await memory.SaveInformationAsync(\n                    collection: \"waf\",\n                    text: text,\n                    id: $\"{Guid.NewGuid()}\",\n                    description: $\"Document: {descr}\").ConfigureAwait(false);\n            }\n            catch (Exception ex)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/samples/dev-team/seed-memory/Program.cs#L21-L57","documentation":"The seed-memory tool throws DirectoryNotFoundException when Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) returns null/empty. Assembly.Location is empty for assemblies loaded from a bundle — most notably single-file publishes and some trimming/AOT scenarios — so the tool cannot locate the PDF file it is supposed to import into semantic memory.","triggerScenarios":"Running seed-memory after 'dotnet publish -p:PublishSingleFile=true'; running the tool from a single-file executable on Linux/macOS; any context where the assembly is loaded from memory rather than a file on disk.","commonSituations":"DevTeam sample deployed as a self-contained single-file binary; CI packaging step publishes single-file and runs the seed tool in the pipeline; .NET 5+ single-file behavior change vs old .NET Framework where Location always worked.","solutions":["Prefer AppContext.BaseDirectory (the directory of the app binary, reliable in single-file mode) instead of Assembly.Location.","Or run the tool via 'dotnet run' / normal (non-single-file) publish while seeding memory, then deploy.","Ensure the WAF PDF file (WafFileName) is copied to the output directory (CopyToOutputDirectory in the csproj) so it sits next to the resolved base path.","If embedded, read the resource stream instead of File.OpenRead on a disk path."],"exampleFix":"// before\nvar asm = Assembly.GetExecutingAssembly();\nvar currentDirectory = Path.GetDirectoryName(asm.Location);\nif (currentDirectory is null) { throw new DirectoryNotFoundException(...); }\n\n// after\nvar currentDirectory = AppContext.BaseDirectory; // valid even for single-file publish\nvar filePath = Path.Combine(currentDirectory, filename);","handlingStrategy":"validation","validationCode":"var baseDir = AppContext.BaseDirectory; // always valid, even for single-file publish\nif (!File.Exists(Path.Combine(baseDir, filename)))\n{\n    Console.Error.WriteLine($\"'{filename}' not found next to the executable in {baseDir}.\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try { await ImportDocumentAsync(memory, WafFileName); } catch (DirectoryNotFoundException) { Console.Error.WriteLine(\"Assembly location unavailable (single-file publish?). Seeding must run from a normal publish or use AppContext.BaseDirectory.\"); }","preventionTips":["Use AppContext.BaseDirectory instead of Assembly.GetExecutingAssembly().Location whenever the binary's folder is needed — Location is empty in single-file bundles.","Mark data files CopyToOutputDirectory in the csproj so they land beside the binary in every publish mode.","Smoke-test publish pipelines (including single-file) with the seeding step before shipping."],"tags":["single-file-publish","assembly-location","dev-team-sample","file-io","dotnet"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}