{"record":{"id":"fd8e383302319d23","repo":"dotnet/BenchmarkDotNet","slug":"0-provided-as-ilcpackages-does-not-exist","errorCode":null,"errorMessage":"{0} provided as ilcPackages does NOT exist","messagePattern":"(.+?) provided as ilcPackages does NOT exist","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchainBuilder.cs","lineNumber":48,"sourceCode":"\n            if (nuGetFeedUrl.IsNotBlank())\n                Feeds[Generator.NativeAotNuGetFeed] = nuGetFeedUrl;\n\n            DisplayName(ilCompilerVersion.IsBlank() ? \"Latest ILCompiler\" : $\"ILCompiler {ilCompilerVersion}\");\n\n            return this;\n        }\n\n        /// <summary>\n        /// creates a NativeAOT toolchain targeting local build of ILCompiler\n        /// Based on https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/nativeaot.md\n        /// </summary>\n        /// <param name=\"ilcPackages\">the path to shipping packages, example: \"C:\\runtime\\artifacts\\packages\\Release\\Shipping\"</param>\n        [PublicAPI]\n        public NativeAotToolchainBuilder UseLocalBuild(DirectoryInfo ilcPackages)\n        {\n            if (!ilcPackages.Exists)\n                throw new DirectoryNotFoundException($\"{ilcPackages} provided as {nameof(ilcPackages)} does NOT exist\");\n\n            Feeds[\"local\"] = ilcPackages.FullName;\n            ilCompilerVersion = \"11.0.0-dev\";\n            Feeds[\"dotnet11\"] = \"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet11/nuget/v3/index.json\";\n            useTempFolderForRestore = true;\n            DisplayName(\"local ILCompiler build\");\n\n            return this;\n        }\n\n        /// <summary>\n        /// The directory to restore packages to (optional).\n        /// </summary>\n        [PublicAPI]\n        [SuppressMessage(\"ReSharper\", \"ParameterHidesMember\")]\n        public NativeAotToolchainBuilder PackagesRestorePath(string packagesRestorePath)\n        {\n            this.packagesRestorePath = packagesRestorePath;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchainBuilder.cs#L30-L66","documentation":"Thrown by NativeAotToolchainBuilder.UseLocalBuild when the DirectoryInfo passed as ilcPackages does not exist on disk. This method configures the NativeAOT toolchain to consume a locally built ILCompiler from a .NET runtime source tree, and it unconditionally registers the path as a NuGet feed and pins the ILCompiler version. A missing directory makes package restore impossible, so it fails fast with DirectoryNotFoundException.","triggerScenarios":"Calling NativeAotToolchain.CreateBuilder().UseLocalBuild(new DirectoryInfo(path)) where path does not resolve to an existing directory. The check is ilcPackages.Exists (DirectoryInfo.Exists, a live filesystem probe). Any non-existent path triggers it regardless of why it is missing.","commonSituations":"Pointing to C:\\runtime\\artifacts\\packages\\Release\\Shipping before building the runtime locally. Using a relative path that resolves against an unexpected working directory. Reusing a path from another machine or after a 'git clean' removed build artifacts. Typing the Shipping vs Debug folder name wrong.","solutions":["Verify the directory exists before calling: check new DirectoryInfo(path).Exists and correct the path to point at the Shipping or Debug packages output (e.g. .../artifacts/packages/Release/Shipping)","Build the .NET runtime locally first so the packages directory is populated (see dotnet/runtime nativeaot build docs)","Use an absolute path to avoid working-directory ambiguity; print ilcPackages.FullName in a diagnostic to confirm what BDN actually resolves"],"exampleFix":"// before\nvar toolchain = NativeAotToolchain.CreateBuilder()\n    .UseLocalBuild(new DirectoryInfo(@\".\\runtime\\packages\\Shipping\")) // wrong path\n    .ToToolchain();\n\n// after (validate + absolute path)\nvar ilcPackages = new DirectoryInfo(@\"C:\\runtime\\artifacts\\packages\\Release\\Shipping\");\nif (!ilcPackages.Exists)\n    throw new InvalidOperationException($\"Build the runtime first; expected packages at {ilcPackages.FullName}\");\n\nvar toolchain = NativeAotToolchain.CreateBuilder()\n    .UseLocalBuild(ilcPackages)\n    .ToToolchain();","handlingStrategy":"validation","validationCode":"// Check the directory exists before handing it to UseLocalBuild.\nusing System.IO;\nusing BenchmarkDotNet.Toolchains.NativeAot;\n\nstatic DirectoryInfo EnsureLocalBuildPackages(string path)\n{\n    var dir = new DirectoryInfo(Path.GetFullPath(path));\n    if (!dir.Exists)\n        throw new DirectoryNotFoundException(\n            $\"ILCompiler packages directory not found: {dir.FullName}. Build the runtime first.\");\n    if (dir.GetFiles(\"*.nupkg\").Length == 0)\n        throw new InvalidOperationException(\n            $\"Directory exists but contains no .nupkg files: {dir.FullName}\");\n    return dir;\n}\n\nvar toolchain = NativeAotToolchain.CreateBuilder()\n    .UseLocalBuild(EnsureLocalBuildPackages(@\"C:\\runtime\\artifacts\\packages\\Release\\Shipping\"))\n    .ToToolchain();","typeGuard":null,"tryCatchPattern":"try { builder.UseLocalBuild(ilcPackages); }\ncatch (DirectoryNotFoundException ex) when (ex.Message.Contains(\"ilcPackages\"))\n{\n    throw new InvalidOperationException(\n        $\"Local ILCompiler packages path is wrong or the runtime was not built: {ilcPackages.FullName}\", ex);\n}","preventionTips":["Always pass an absolute path to UseLocalBuild; relative paths resolve against the process working directory.","After building dotnet/runtime, confirm the Shipping/Debug packages directory contains .nupkg files before configuring BDN.","Wrap the path in a helper that checks .Exists and prints FullName in diagnostics so failures are self-explanatory."],"tags":["nativeaot","local-build","filesystem","ilcompiler","toolchain"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}