{"record":{"id":"3ba4e4cf0221536c","repo":"lepoco/wpfui","slug":"could-not-determine-the-working-directory","errorCode":null,"errorMessage":"Could not determine the working directory.","messagePattern":"Could not determine the working directory\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf.Ui.FontMapper/Program.cs","lineNumber":15,"sourceCode":"// This Source Code Form is subject to the terms of the MIT License.\n// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.\n// Copyright (C) Leszek Pomianowski and WPF UI Contributors.\n// All Rights Reserved.\n\nusing System.Net.Http;\nusing System.Net.Http.Json;\nusing Wpf.Ui.FontMapper;\n\nConsole.WriteLine(\"Fluent System Icons Mapper\");\nSystem.Diagnostics.Debug.WriteLine(\"INFO | Fluent System Icons Mapper\", \"Wpf.Ui.FontMapper\");\n\nvar workingDirectory =\n    Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)\n    ?? throw new InvalidOperationException(\"Could not determine the working directory.\");\n\nvar regularIcons = new FontSource(\n    \"SymbolRegular\",\n    \"Represents a list of regular Fluent System Icons <c>v.{{FLUENT_SYSTEM_ICONS_VERSION}}</c>.\\n<para>May be converted to <see langword=\\\"char\\\"/> using <c>GetGlyph()</c> or to <see langword=\\\"string\\\"/> using <c>GetString()</c></para>\",\n    @\"https://raw.githubusercontent.com/microsoft/fluentui-system-icons/main/fonts/FluentSystemIcons-Regular.json\",\n    \"generated\\\\SymbolRegular.cs\"\n);\nvar filledIcons = new FontSource(\n    \"SymbolFilled\",\n    \"Represents a list of filled Fluent System Icons <c>v.{{FLUENT_SYSTEM_ICONS_VERSION}}</c>.\\n<para>May be converted to <see langword=\\\"char\\\"/> using <c>GetGlyph()</c> or to <see langword=\\\"string\\\"/> using <c>GetString()</c></para>\",\n    @\"https://raw.githubusercontent.com/microsoft/fluentui-system-icons/main/fonts/FluentSystemIcons-Filled.json\",\n    \"generated\\\\SymbolFilled.cs\"\n);\n\nTask<string> FetchVersion()\n{\n    // using var httpClient = new HttpClient();\n    // httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(\"Mozilla/5.0 (compatible; AcmeInc/1.0)\");","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui.FontMapper/Program.cs#L1-L33","documentation":"This is in the Wpf.Ui.FontMapper code-generation tool (a console Program), not the runtime library. It derives its working directory from Assembly.GetExecutingAssembly().Location. Under single-file / trimmed publishing, Location returns an empty string, so Path.GetDirectoryName returns null and the tool throws InvalidOperationException because it has nowhere to write the generated SymbolRegular.cs/SymbolFilled.cs files.","triggerScenarios":"Running the FontMapper generator from a single-file publish, an AOT/trimmed executable, or any host where Assembly.Location is unavailable; running via certain test runners that shadow-copy with no Location.","commonSituations":"Publishing the FontMapper as a single-file exe; .NET trimming/NativeAOT; invoking the assembly through a loader that strips Location.","solutions":["Run the tool from a normal (non-single-file) build output where Location is populated.","If you must single-file publish, patch the tool to use AppContext.BaseDirectory instead of Assembly.Location.","Run via 'dotnet run' against the project rather than a published single-file binary."],"exampleFix":"// before\nvar workingDirectory =\n    Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)\n    ?? throw new InvalidOperationException(\"Could not determine the working directory.\");\n\n// after\nvar workingDirectory =\n    Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)\n    ?? AppContext.BaseDirectory;\n// or unconditionally:\nvar workingDirectory = AppContext.BaseDirectory;","handlingStrategy":"validation","validationCode":"var workingDirectory =\n    Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)\n    ?? AppContext.BaseDirectory;\nif (!Directory.Exists(workingDirectory)) throw new InvalidOperationException(\"No working dir.\");","typeGuard":"static bool HasWorkingDirectory()\n    => !string.IsNullOrEmpty(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))\n       || Directory.Exists(AppContext.BaseDirectory);","tryCatchPattern":"try { /* run mapper */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"working directory\"))\n{\n    Console.Error.WriteLine(\"Run from a normal build output, not a single-file publish.\");\n}","preventionTips":["Run the FontMapper from standard build output (dotnet run), not single-file publish.","If single-file is required, patch the tool to use AppContext.BaseDirectory.","Avoid trimmed/NativeAOT for this generator since it relies on Assembly.Location."],"tags":["font-mapper","path","single-file","tooling"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}