{"record":{"id":"2bfcd5aa853c5ee4","repo":"Unity-Technologies/UnityCsReference","slug":"value-cannot-be-null","errorCode":null,"errorMessage":"Value cannot be null.","messagePattern":"Value cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/FileUtil.bindings.cs","lineNumber":22,"sourceCode":"\nusing System;\nusing UnityEngine;\nusing UnityEngine.Bindings;\nusing System.IO;\n\n\nnamespace UnityEditor\n{\n    // Lets you do ''move'', ''copy'', ''delete'' operations over files or directories\n    [NativeHeader(\"Runtime/Utilities/FileUtilities.h\")]\n    [NativeHeader(\"Runtime/Utilities/File.h\")]\n    [NativeHeader(\"Editor/Platform/Interface/EditorUtility.h\")]\n    public partial class FileUtil\n    {\n        // Deletes a file or a directory given a path.\n        public static bool DeleteFileOrDirectory(string path)\n        {\n            if (path is null) throw new ArgumentNullException(\"path\");\n            if (path == string.Empty) throw new ArgumentException(\"path\", \"The path cannot be empty.\");\n\n            return DeleteFileOrDirectoryInternal(path);\n        }\n\n        [FreeFunction(\"DeleteFileOrDirectory\")]\n        private static extern bool DeleteFileOrDirectoryInternal(string path);\n\n        [FreeFunction(\"IsPathCreated\")]\n        private static extern bool PathExists(string path);\n\n        // Copies a file or directory.\n        public static void CopyFileOrDirectory(string source, string dest)\n        {\n            CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptionWhenNullOrEmpty(source, dest);\n\n            if (PathExists(dest))\n            {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/FileUtil.bindings.cs#L4-L40","documentation":"FileUtil.DeleteFileOrDirectory throws ArgumentNullException (whose default message is 'Value cannot be null.') when the path argument is the null reference, before it ever reaches the native delete. An empty string is handled separately with an ArgumentException. This is the standard null-guard on a managed-to-native file operation.","triggerScenarios":"Calling DeleteFileOrDirectory(null) directly, or passing a variable that was never assigned (e.g. a missing AssetDatabase.GUIDToAssetPath result that returned null/empty before null-coalescing).","commonSituations":"Clean-up code that deletes a temp asset whose path lookup failed silently. Asset pipeline scripts deleting by a GUID that no longer exists. Build scripts that try to remove an optional output file that was never produced.","solutions":["Null-check the path before calling: if (!string.IsNullOrEmpty(path)) FileUtil.DeleteFileOrDirectory(path);.","If the path comes from GUIDToAssetPath/Selection, validate the lookup returned a non-empty string first.","Use the empty-string ArgumentException (separate path) to distinguish 'no path supplied' from 'path supplied but null'."],"exampleFix":"// before\nFileUtil.DeleteFileOrDirectory(maybePath);\n// after\nif (!string.IsNullOrEmpty(maybePath))\n    FileUtil.DeleteFileOrDirectory(maybePath);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(path))\n    FileUtil.DeleteFileOrDirectory(path);","typeGuard":"static bool IsDeletablePath(string p) => !string.IsNullOrEmpty(p);","tryCatchPattern":null,"preventionTips":["Centralise delete calls behind a helper that null/empty-checks first.","Validate GUIDToAssetPath/Selection results before deriving a path to delete.","Distinguish null (missing value) from empty (lookup resolved to nothing) in error logs."],"tags":["null-argument","filesystem","delete","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}