JosefNemec/Playnite · error · FileNotFoundException
Cannot add file to database, file not found.
Error message
Cannot add file to database, file not found.
What it means
Thrown by DatabaseAPI.AddFile when the local file referenced by `path` does not exist on disk before the database attempts to import it. Playnite refuses to add a database entry for a missing file because the GameDatabase.AddFile call downstream would read/copy bytes that are not there. The check is an explicit File.Exists guard at the API boundary, distinct from the lower-level database read failures.
Source
Thrown at source/Playnite/API/DatabaseAPI.cs:60
{
get => database?.DatabasePath;
}
public bool IsOpen
{
get => database?.IsOpen == true;
}
public DatabaseAPI(GameDatabase database)
{
this.database = database;
}
public string AddFile(string path, Guid parentId)
{
if (!File.Exists(path))
{
throw new FileNotFoundException("Cannot add file to database, file not found.");
}
return database.AddFile(path, parentId, false, CancellationToken.None);
}
public void SaveFile(string id, string path)
{
database.CopyFile(id, path);
}
public void RemoveFile(string id)
{
database.RemoveFile(id);
}
public IDisposable BufferedUpdate()
{
return database.BufferedUpdate();
View on GitHub (pinned to 5911f4e964)
Solutions
- Verify File.Exists(path) immediately before calling AddFile and skip/log if false.
- Resolve `path` to an absolute path with Path.GetFullPath and confirm the directory exists first.
- If the file comes from a download or copy, await/flush that operation to completion before AddFile.
- Re-check the path after long-running work, since the file may have been removed by AV or cleanup.
Example fix
// before
db.AddFile(tempCover, game.Id);
// after
if (!File.Exists(tempCover))
{
logger.Warn($"Cover missing, skipping: {tempCover}");
return;
}
db.AddFile(tempCover, game.Id); Defensive patterns
Strategy: validation
Validate before calling
if (!File.Exists(Path.GetFullPath(path)))
{
return; // or log and skip
}
var id = api.Database.AddFile(path, parentId); Prevention
- Always File.Exists-check at the boundary before AddFile.
- Resolve to absolute paths with Path.GetFullPath before checking.
- Await downloads/copies to completion before importing.
- Re-check existence after any long-running prior step.
When it happens
Trigger: Calling api.Database.AddFile(path, parentId) where `path` is relative, points to a temp file already moved/deleted, a download target that hasn't finished writing, or a path with the wrong casing/separator on the current OS. Any string for which File.Exists returns false trips it.
Common situations: Extension code that downloads cover art to a temp dir and adds it before the download stream closes; passing a URL or a database file id instead of a real filesystem path; running on a path that exceeds MAX_PATH before Paths.FixPathLength is applied; antivirus quarantining the file between creation and AddFile.
Related errors
- Failed to read {path}
- Failed to write to {path}
- Failed to delete {path}
- Source directory does not exist or could not be found: {sour
- Root directory is not set or does not exist.
AI-assisted analysis of JosefNemec/Playnite@5911f4e964 (2026-08-13).
Data as JSON: /api/errors/4787954196a3ad28.
Report an issue: GitHub.