{"record":{"id":"fec21f31f435087b","repo":"restsharp/RestSharp","slug":"file-not-found","errorCode":null,"errorMessage":"File not found","messagePattern":"File not found","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/RestSharp/Parameters/FileParameter.cs","lineNumber":103,"sourceCode":"    /// <param name=\"contentType\">Optional: parameter content type, default is \"application/g-zip\"</param>\n    /// <param name=\"options\">File parameter options</param>\n    /// <returns>The <see cref=\"FileParameter\" /> using the default content type.</returns>\n    public static FileParameter Create(\n        string                name,\n        Func<Stream>          getFile,\n        string                fileName,\n        ContentType?          contentType = null,\n        FileParameterOptions? options     = null\n    )\n        => new(name, fileName, getFile, contentType, options ?? new FileParameterOptions());\n\n    public static FileParameter FromFile(\n        string                fullPath,\n        string?               name        = null,\n        ContentType?          contentType = null,\n        FileParameterOptions? options     = null\n    ) {\n        if (!File.Exists(Ensure.NotEmptyString(fullPath, nameof(fullPath)))) throw new FileNotFoundException(\"File not found\", fullPath);\n\n        var fileName      = Path.GetFileName(fullPath);\n        var parameterName = name ?? fileName;\n\n        return new(parameterName, fileName, GetFile, contentType, options ?? new FileParameterOptions());\n\n        Stream GetFile() => File.OpenRead(fullPath);\n    }\n}\n\n[PublicAPI]\npublic class FileParameterOptions {\n    public bool DisableFilenameStar     { get; set; } = true;\n    public bool DisableFilenameEncoding { get; set; }\n}\n","sourceCodeStart":85,"sourceCodeEnd":119,"githubUrl":"https://github.com/restsharp/RestSharp/blob/6a5082169257438cd085f822f050d93256a8e499/src/RestSharp/Parameters/FileParameter.cs#L85-L119","documentation":"Thrown by FileParameter.FromFile when the specified fullPath does not exist on disk (File.Exists returns false). Ensures the file is present before attempting to open a read stream for upload.","triggerScenarios":"Calling FileParameter.FromFile(path) or request.AddFile(path) where path points to a non-existent, moved, or inaccessible file.","commonSituations":"Relative path resolved against an unexpected working directory; file deleted between check and upload; path from config pointing to a build artifact not yet produced; permissions/typo in the path.","solutions":["Verify the file exists (File.Exists) and the path is absolute before calling FromFile.","Use AppContext.BaseDirectory or Path.Combine to anchor relative paths.","Ensure the file is produced (built/copied) before the upload step runs."],"exampleFix":"// before\nrequest.AddFile(\"file\", config.AttachmentPath);\n\n// after\nvar fullPath = Path.Combine(AppContext.BaseDirectory, config.AttachmentPath);\nif (!File.Exists(fullPath))\n    throw new FileNotFoundException($\"Attachment not found: {fullPath}\");\nrequest.AddFile(\"file\", fullPath);","handlingStrategy":"validation","validationCode":"if (!File.Exists(path)) throw new FileNotFoundException(\"File not found\", path);","typeGuard":null,"tryCatchPattern":"try { request.AddFile(\"file\", path); } catch (FileNotFoundException) { /* handle missing file gracefully */ }","preventionTips":["Use absolute paths anchored to AppContext.BaseDirectory for bundled files.","Check File.Exists before referencing files for upload.","Ensure build/copy steps produce the file before the upload runs."],"tags":["file","upload","filesystem","request"],"backgroundTag":null,"analyzedSha":"6a5082169257438cd085f822f050d93256a8e499","analyzedAt":"2026-08-13T20:38:25.807Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}