{"record":{"id":"8afa13afe18e2c0a","repo":"DevToys-app/DevToys","slug":"unable-to-find-the-indicated-file-8afa13","errorCode":null,"errorMessage":"Unable to find the indicated file.","messagePattern":"Unable to find the indicated file\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/app/dev/platforms/desktop/DevToys.Windows/Core/FileStorage.cs","lineNumber":36,"sourceCode":"    {\n        if (!Path.IsPathRooted(relativeOrAbsoluteFilePath))\n        {\n            relativeOrAbsoluteFilePath = Path.Combine(AppCacheDirectory, relativeOrAbsoluteFilePath);\n        }\n\n        return File.Exists(relativeOrAbsoluteFilePath);\n    }\n\n    public FileStream OpenReadFile(string relativeOrAbsoluteFilePath)\n    {\n        if (!Path.IsPathRooted(relativeOrAbsoluteFilePath))\n        {\n            relativeOrAbsoluteFilePath = Path.Combine(AppCacheDirectory, relativeOrAbsoluteFilePath);\n        }\n\n        if (!File.Exists(relativeOrAbsoluteFilePath))\n        {\n            throw new FileNotFoundException(\"Unable to find the indicated file.\", relativeOrAbsoluteFilePath);\n        }\n\n        return new FileStream(relativeOrAbsoluteFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, SandboxedFileReader.BufferSize, FileOptions.Asynchronous | FileOptions.SequentialScan);\n    }\n\n    public FileStream OpenWriteFile(string relativeOrAbsoluteFilePath, bool replaceIfExist)\n    {\n        if (!Path.IsPathRooted(relativeOrAbsoluteFilePath))\n        {\n            relativeOrAbsoluteFilePath = Path.Combine(AppCacheDirectory, relativeOrAbsoluteFilePath);\n        }\n\n        if (File.Exists(relativeOrAbsoluteFilePath) && replaceIfExist)\n        {\n            File.Delete(relativeOrAbsoluteFilePath);\n        }\n\n        string parentDirectory = Path.GetDirectoryName(relativeOrAbsoluteFilePath)!;","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/DevToys-app/DevToys/blob/7e12df8448aa1f6aec4a8736b3e06a1c90530715/src/app/dev/platforms/desktop/DevToys.Windows/Core/FileStorage.cs#L18-L54","documentation":"Thrown by DevToys.Windows FileStorage.OpenReadFile after resolving a relative path against AppCacheDirectory and finding the file absent via File.Exists. It is the Windows platform's implementation of the shared IFileStorage.OpenReadFile contract. FileNotFoundException carries the resolved path.","triggerScenarios":"Calling IFileStorage.OpenReadFile with a relative path that does not exist under AppCacheDirectory; an absolute path to a missing file; a file deleted between the existence check and the open (TOCTOU); a path that points into a location the packaged app cannot reach without broker access.","commonSituations":"MSIX/sandboxed app cache layout differing from dev; a file expected from a previous run that was cleaned on update; path with forward slashes or case that resolves differently; producer step failed so the file was never written.","solutions":["Call IFileStorage.FileExists(path) immediately before OpenReadFile and handle the false case.","Inspect the resolved path (AppCacheDirectory + relative) to confirm it is the expected location.","Ensure the producer (OpenWriteFile) completed before the consumer reads.","For packaged/MSIX apps, confirm the path is inside the permitted app data folder.","Catch FileNotFoundException and recover (recreate, reprompt, skip)."],"exampleFix":"// before\nusing FileStream stream = fileStorage.OpenReadFile(relativePath);\n\n// after\nif (!fileStorage.FileExists(relativePath))\n{\n    return; // or recreate / reprompt\n}\nusing FileStream stream = fileStorage.OpenReadFile(relativePath);","handlingStrategy":"validation","validationCode":"string resolved = Path.IsPathRooted(path) ? path : Path.Combine(fileStorage.AppCacheDirectory, path);\nif (!File.Exists(resolved))\n{\n    return; // or recreate / reprompt\n}\nusing FileStream stream = fileStorage.OpenReadFile(path);","typeGuard":null,"tryCatchPattern":"try\n{\n    using FileStream stream = fileStorage.OpenReadFile(path);\n}\ncatch (FileNotFoundException ex)\n{\n    // expected missing file — recreate or skip\n}","preventionTips":["Precede OpenReadFile with FileExists; for packaged/MSIX apps confirm the path is inside the permitted app-data folder.","Log the resolved path (AppCacheDirectory + relative) for missing-file diagnostics.","Ensure the producer (OpenWriteFile) completed before the consumer reads.","Catch FileNotFoundException at the call site and degrade gracefully."],"tags":["csharp","file-io","filestorage","windows","toctou"],"backgroundTag":null,"analyzedSha":"7e12df8448aa1f6aec4a8736b3e06a1c90530715","analyzedAt":"2026-08-13T10:27:33.924Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}