【问题标题】:Loading an external DLL into Blazor from local machine从本地计算机将外部 DLL 加载到 Blazor
【发布时间】:2020-11-24 08:53:12
【问题描述】:

我正在尝试在运行时将程序集加载到 Blazor 应用程序,如图所示 here

但是,我在尝试在 OnInitializedAsync() 中加载程序集时遇到错误:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常渲染组件:响应状态码不 表示成功:404(未找到)。 System.Net.Http.HttpRequestException:响应状态代码不 表示成功:404(未找到)。在 System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode () 在 :0 在 System.Net.Http.HttpClient.GetByteArrayAsyncCore (System.Threading.Tasks.Task1[TResult] getTask) <0x61d5a18 + 0x0010e> in <filename unknown>:0 at WebAssembly.Client.Pages.Compiler.GetDlltoBrowser (System.Collections.Generic.List1[T] 引用)[0x0008f] in C:\Users\User\source\repos\CInteractiveShell-Sample\WebAssembly\Client\Pages\Compiler.razor:200 在 WebAssembly.Client.Pages.Compiler.OnInitializedAsync () [0x00240] 在 C:\Users\User\source\repos\CInteractiveShell-Sample\WebAssembly\Client\Pages\Compiler.razor:47 在 Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () 在 :0 处 Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) 在 :0

我的包参考是:

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.7.0-4.final" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />

【问题讨论】:

  • 您的错误代码是 HTTP 404,这意味着您尝试加载的 DLL 在服务器上找不到。尝试使用 Postman 断言服务器调用首先工作。

标签: c# asp.net-core blazor blazor-webassembly


【解决方案1】:

可能发生错误的地方

框架和应用代码可能会在以下任何位置触发未处理的异常:

  1. 组件实例化。
  2. 生命周期方法。
  3. 渲染逻辑。
  4. 事件处理程序。
  5. 组件处置。
  6. JavaScript 互操作。
  7. Blazor 服务器重新呈现

我相信您的问题必须在此得到解决。 [Handle errors in ASP.NET Core Blazor apps]1

我最初的猜测是生命周期方法将根据您提供的信息解决您的问题。

如果您正在寻找确切的解决方案,请在快照方面分享更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 2021-09-20
    • 2020-05-01
    相关资源
    最近更新 更多