{"record":{"id":"d6ab0b3a543463b9","repo":"microsoft/semantic-kernel","slug":"plugins-directory-not-found-the-app-needs-the-plu","errorCode":null,"errorMessage":"Plugins directory not found. The app needs the plugins from the repo to work.","messagePattern":"Plugins directory not found\\. The app needs the plugins from the repo to work\\.","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/TelemetryWithAppInsights/RepoUtils/RepoFiles.cs","lineNumber":32,"sourceCode":"        const string Folder = \"prompt_template_samples\";\n\n        static bool SearchPath(string pathToFind, out string result, int maxAttempts = 10)\n        {\n            var currDir = Path.GetFullPath(Assembly.GetExecutingAssembly().Location);\n            bool found;\n            do\n            {\n                result = Path.Join(currDir, pathToFind);\n                found = Directory.Exists(result);\n                currDir = Path.GetFullPath(Path.Combine(currDir, \"..\"));\n            } while (maxAttempts-- > 0 && !found);\n\n            return found;\n        }\n\n        if (!SearchPath(Folder, out var path))\n        {\n            throw new DirectoryNotFoundException(\"Plugins directory not found. The app needs the plugins from the repo to work.\");\n        }\n\n        return path;\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":38,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/TelemetryWithAppInsights/RepoUtils/RepoFiles.cs#L14-L38","documentation":"RepoFiles.SearchPath walks up to maxAttempts parent directories from the current directory looking for a folder (e.g., 'Plugins'). If it is not found within the attempt budget, the method throws DirectoryNotFoundException. This is used to locate the sample's plugins folder relative to the repo root at runtime.","triggerScenarios":"Running the TelemetryWithAppInsights sample from a working directory that is more than maxAttempts levels below the plugins folder, or from outside the repo entirely so the plugins folder is never an ancestor.","commonSituations":"Running the published app or a unit test from bin/Release/netX.0/ when the repo is deeply nested; running inside a Docker container where the repo isn't mounted; cloning the repo but not including the Plugins directory; maxAttempts is too small for deep working-directory nesting.","solutions":["Run the sample from a directory within the repo (e.g., the project folder) so the upward search reaches the Plugins folder quickly.","Increase the maxAttempts parameter in the SearchPath call to accommodate deeper directory nesting.","Copy or symlink the Plugins directory into the app's output folder.","Make the Plugins path configurable via environment variable or appsettings so it doesn't depend on the repo structure."],"exampleFix":"// before\nif (!SearchPath(Folder, out var path))\n{\n    throw new DirectoryNotFoundException(\"Plugins directory not found. The app needs the plugins from the repo to work.\");\n}\n\n// after — allow override via environment variable, then fall back to search\nvar pluginsDir = Environment.GetEnvironmentVariable(\"PLUGINS_DIR\");\nif (!string.IsNullOrEmpty(pluginsDir) && Directory.Exists(pluginsDir))\n    return pluginsDir;\nif (!SearchPath(Folder, out var path))\n    throw new DirectoryNotFoundException($\"Plugins directory not found at '{Folder}'. Set PLUGINS_DIR or run from within the repo.\");\nreturn path;","handlingStrategy":"validation","validationCode":"// Check an environment override first, then verify existence\nvar dir = Environment.GetEnvironmentVariable(\"PLUGINS_DIR\") ?? Path.Combine(AppContext.BaseDirectory, \"Plugins\");\nif (!Directory.Exists(dir))\n    throw new DirectoryNotFoundException($\"Plugins directory not found at '{dir}'. Set PLUGINS_DIR or run from the repo.\");","typeGuard":null,"tryCatchPattern":"try { return RepoFiles.FindPlugins(); } catch (DirectoryNotFoundException) { /* copy plugins to output or adjust CWD */ }","preventionTips":["Make resource paths configurable via environment variables.","Ship required directories as content with CopyToOutputDirectory in the .csproj.","Always run samples from within the repo structure during development."],"tags":["directory-not-found","filesystem","plugins","samples","path-search"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}