tomRedox
tomRedox

Reputation: 30433

"Cannot read property '_blazorFilesById' of null error" with Blazor InputFile component

I've started getting this error from my Blazor WebAssembly app:

"Cannot read property '_blazorFilesById' of null error" with Blazor app

I'm assuming that's related to the InputFile component I'm using, which has been working fine.

I've tried restarting VS, clean & rebuilding, restarting IIS and killing Chrome all to no avail. What could be causing this?

Upvotes: 25

Views: 7801

Answers (4)

cibermax
cibermax

Reputation: 1

add async method and put next code

await using FileStream fs = new(path, FileMode.Create);
await img.BrowserFile.OpenReadStream().CopyToAsync(fs);

for me this work

Upvotes: 0

Tyrone Harding
Tyrone Harding

Reputation: 427

this is happening because you are most likely calling StatehasChanged in the onchange function

Upvotes: 4

Debraj Banerjee
Debraj Banerjee

Reputation: 321

I tried keeping the InputFile component inside a Div and conditionally (based on a bool @uploadingInProgress) hiding the Div (esp. during the upload progress) works perfectly

Upvotes: 4

tomRedox
tomRedox

Reputation: 30433

This turns out to be because I'd added conditional code to hide the InputFile component on the page. Doing that will cause the error as explained in this post on GitHub by BtbN:

Did you modify your page, so the InputFile element is not rendered anymore? It has to stay present, otherwise the browser cleans up any resources associated with it.

Upvotes: 55

Related Questions