我创建了默认的Blazor WebAssembly应用程序以测试BlazorInputFile组件。
每当我启动该应用程序时,如果我转到创建的简单页面(仅带有上传文件的选项),就会收到以下错误消息,如下所述。但是,如果我只是刷新页面,该错误就会消失并且不会再次出现。
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer [100] 未处理的异常呈现组件:在“窗口”中找不到“ BlazorInputFile”。 p / <@https:// localhost:5003 / _framework / blazor.webassembly.js:1:9130
我遵循了本文建议的步骤: https://www.mikesdotnetting.com/article/341/uploading-files-in-blazor
<script src="_content/BlazorInputFile/inputfile.js"></script>
仅当我使用Firefox浏览器时才会出现此错误,如果使用Microsoft Edge,则不会出现此错误。
我创建的页面很简单:
@page "/singlefile"
<h1>Single file</h1>
<p>A single file input that uploads automatically on file selection</p>
<InputFile OnChange="HandleSelection" />
<p>@status</p>
@code {
string status;
async Task HandleSelection(IFileListEntry[] files)
{
var file = files.FirstOrDefault();
if (file != null)
{
// Just load into .NET memory to show it can be done
// Alternatively it could be saved to disk, or parsed in memory, or similar
var ms = new MemoryStream();
await file.Data.CopyToAsync(ms);
status = $"Finished loading {file.Size} bytes from {file.Name}";
}
}
}
答案 0 :(得分:0)
我已经通过禁用adblocker解决了这一问题。显然,它导致了此异常的发生。