"Cannot read property '_blazorFilesById' of null error" 使用 Blazor InputFile 组件

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

我的 Blazor WebAssembly 应用程序开始出现此错误:

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

我假设这与我正在使用的 InputFile component 有关,它一直运行良好。

我试过重新启动 VS、清理和重建、重新启动 IIS 并终止 Chrome 都无济于事。可能是什么原因造成的?

原来是因为我添加了条件代码来隐藏页面上的 InputFile 组件。这样做会导致 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.

我尝试将 InputFile 组件保留在 Div 中,并且有条件地(基于 bool @uploadingInProgress)隐藏 Div(尤其是在上传过程中)效果很好