dotnet/aspnetcore · error · Error
There is no file with ID
Error message
There is no file with ID ${fileId}. The file list may have changed. See https://aka.ms/aspnet/blazor-input-file-multiple-selections. What it means
`getFileById` looks up a browser file the user selected via Blazor's `InputFile` component by indexing `elem._blazorFilesById[fileId]`. Each selected file is assigned an incremental ID by the framework; the map only lives for the lifetime of the current input's file list. If the requested ID is absent the lookup throws, pointing at the multiple-selections guidance because re-picking or clearing files renumbers the list.
Solutions
- Re-read files in the same `OnInputFileChange` handler where the `IBrowserFile` was obtained — do not retain the id past the current selection.
- If you must process asynchronously, copy the stream to memory/storage first, then release the id before the user can change the selection.
- Clear the input (`InputFile.Reset()`) deliberately rather than letting the user re-pick, so the id lifecycle is explicit.
- On Blazor Server, guard long-running file work against circuit reconnects which can invalidate the client-side file map.
Example fix
// before
var file = e.GetMultipleFiles(int.MaxValue)[0];
// ...user picks new files, then later:
await using var fs = file.OpenReadStream(); // stale id -> throw
// after
var file = e.GetMultipleFiles(int.MaxValue)[0];
await using var ms = new MemoryStream();
await using (var fs = file.OpenReadStream(maxAllowedSize: long.MaxValue))
await fs.CopyToAsync(ms); // consume immediately, same selection Defensive patterns
Strategy: validation
Validate before calling
function hasFile(elem: HTMLInputElement, fileId: number): boolean {
return !!(elem as any)._blazorFilesById && fileId in (elem as any)._blazorFilesById;
} Try / catch
try { return await readFileData(elem, fileId); }
catch (e) { if (/no file with ID/.test(e.message)) { /* re-prompt user or abort */ return null; } throw e; } Prevention
- Consume IBrowserFile streams in the same OnInputFileChange that produced them.
- Copy file bytes to durable storage before allowing the selection to change.
- Reset the InputFile deliberately rather than letting re-selection renumber ids.
- Do not cache file ids across circuit reconnects on Blazor Server.
When it happens
Trigger: Calling `readFileData`/`getFileById` (through `IBrowserFile` open-read APIs or `InputFile` JS interop) with a `fileId` that was never assigned, was assigned on a different input element, or became invalid after the file list changed (re-select, clear, or multiple-selection changes).
Common situations: Caching an `IBrowserFile` reference across postbacks in Blazor Server after the input's file list was replaced; passing an id from a disposed/cleared `<InputFile>`; using the same input for multiple selection rounds and referencing a stale id from an earlier round; desync between server-tracked ids and client `_blazorFilesById` after a reconnect.
Related errors
- Interop methods are already registered for renderer
- Interop methods are not registered for renderer
- No interop methods are registered for renderer
- Cannot update existing state: previous state has not been…
- Could not find ' ' (' ' was undefined).
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/01df505ee37907f5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Web.JS/src/InputFile.ts:117
contentType: format,
blob: resizedImageBlob ? resizedImageBlob : originalFile.blob,
};
elem._blazorFilesById[result.id] = result;
return result;
}
async function readFileData(elem: InputElement, fileId: number): Promise<Blob> {
const file = getFileById(elem, fileId);
return file.blob;
}
export function getFileById(elem: InputElement, fileId: number): BrowserFile {
const file = elem._blazorFilesById[fileId];
if (!file) {
throw new Error(`There is no file with ID ${fileId}. The file list may have changed. See https://aka.ms/aspnet/blazor-input-file-multiple-selections.`);
}
return file;
}
View on GitHub (pinned to 3600ca084e)