20

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?

tomRedox
  • 28,092
  • 24
  • 117
  • 154

3 Answers3

36

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.

tomRedox
  • 28,092
  • 24
  • 117
  • 154
  • 2
    Good tip. I had my file input control on modal window. Inside the modal window a thread was fired off to process the file, but the modal window closed quickly, before the thread had completed, and got the same error. – ScottSto Jul 14 '22 at 19:01
  • A great solution. I was stack for several hours for that – mnu-nasir Nov 04 '22 at 18:59
  • This worked for me. I had my form wrapped in a if (_isLoading) {} and that caused this. – Pär Sandgren Jul 17 '23 at 22:05
4

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

Debraj Banerjee
  • 201
  • 2
  • 3
2

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

Tyrone Harding
  • 187
  • 1
  • 4