{"record":{"id":"ca11c0f76819eea8","repo":"Unity-Technologies/UnityCsReference","slug":"no-such-file-or-directory","errorCode":null,"errorMessage":"No such file or directory.","messagePattern":"No such file or directory\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildPipeline/BuildPlayerContext.cs","lineNumber":95,"sourceCode":"        ///<param name=\"directoryOrFile\">Path representing an existing file or directory. If the path doesn't exist, this function throws a FileNotFoundException.</param>\n        ///<param name=\"pathInStreamingAssets\">The path within the StreamingAssets folder at which to place the additional assets. If null, the file or directory is placed directly in the StreamingAssets folder.</param>\n        public void AddAdditionalPathToStreamingAssets(string directoryOrFile, string pathInStreamingAssets = null)\n        {\n            NPath sourcePath = directoryOrFile;\n            if (sourcePath.DirectoryExists())\n            {\n                NPath targetPath = pathInStreamingAssets ?? \"\";\n                foreach (var file in sourcePath.Files(true))\n                    AddAdditionalFileToStreamingAssets(file, targetPath.Combine(file.RelativeTo(sourcePath)));\n            }\n            else if (sourcePath.FileExists())\n            {\n                NPath targetPath = pathInStreamingAssets ?? sourcePath.FileName;\n                AddAdditionalFileToStreamingAssets(sourcePath, targetPath);\n            }\n            else\n            {\n                throw new FileNotFoundException(\"No such file or directory.\", sourcePath.ToString());\n            }\n        }\n\n        private void AddAdditionalFileToStreamingAssets(NPath sourceFile, NPath targetPath)\n        {\n            if (StreamingAssetFiles.TryGetValue(targetPath, out var existingValue))\n            {\n                // If someone is adding the same file more than once we ignore subsequent adds\n                if (existingValue == sourceFile)\n                    return;\n\n                // Throw an exception and tell the user what the problem is\n                throw new ArgumentException(\n                    $\"Unable to add '{sourceFile}' to StreamingAssets. An entry for '{targetPath}' has already been added, '{existingValue}'.\");\n            }\n            StreamingAssetFiles.Add(targetPath, sourceFile);\n        }\n    }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildPipeline/BuildPlayerContext.cs#L77-L113","documentation":"Thrown by BuildPlayerContext.AddAdditionalFileToStreamingAssets when the source path is neither an existing directory nor an existing file. The method uses NPath to check for directory existence (Files enumeration) and file existence, and throws FileNotFoundException when neither resolves.","triggerScenarios":"Calling AddAdditionalFileToStreamingAssets with a sourcePath that points to a non-existent file or directory — e.g., a path from a build script that hasn't been generated yet, a path with a typo, or a path relative to the wrong working directory.","commonSituations":"Build scripts that add pre-generated assets (license files, config, native plugins) to StreamingAssets before the file is produced, CI environments where a preceding step failed silently, or paths constructed from variables that are empty or incorrectly resolved.","solutions":["Verify the source path exists with File.Exists or Directory.Exists before calling AddAdditionalFileToStreamingAssets.","Ensure any file-generation step that feeds into this call has completed successfully.","Log the absolute resolved path in the error to catch working-directory or variable issues."],"exampleFix":"// before\ncontext.AddAdditionalFileToStreamingAssets(\"./BuildOutput/license.dat\", \"license.dat\");\n// fails if ./BuildOutput/license.dat doesn't exist yet\n\n// after\nstring source = Path.GetFullPath(\"./BuildOutput/license.dat\");\nif (!File.Exists(source))\n    throw new FileNotFoundException($\"Pre-build artifact missing: {source}\");\ncontext.AddAdditionalFileToStreamingAssets(source, \"license.dat\");","handlingStrategy":"validation","validationCode":"void AddToStreamingAssetsSafe(BuildPlayerContext ctx, string sourcePath, string targetPath)\n{\n    string abs = Path.GetFullPath(sourcePath);\n    if (!File.Exists(abs) && !Directory.Exists(abs))\n        throw new FileNotFoundException(\n            $\"StreamingAssets source does not exist: {abs}\");\n    ctx.AddAdditionalFileToStreamingAssets(abs, targetPath);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve source paths to absolute and verify File.Exists or Directory.Exists before calling AddAdditionalFileToStreamingAssets.","Ensure any file-generation steps complete before the streaming-assets phase.","Log the absolute path on failure to catch working-directory issues."],"tags":["unity","build-pipeline","streaming-assets","file-not-found","buildplayer-context"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}