【问题标题】:Random "Error: The circuit failed to initialize" with Blazor app使用 Blazor 应用程序随机出现“错误:电路无法初始化”
【发布时间】:2020-07-13 21:30:00
【问题描述】:

我目前正在开发 Blazor 服务器端应用程序,并且在启动页面后直接遇到随机错误。当我按下 F5 按钮或单击索引页面上的任何链接时,页面会重新加载并且错误不会再次出现。错误消息非常通用,我真的不知道从哪里开始调试。即使我完全删除了作为起始页的 Index.razor 页面的内容,也会发生错误。任何想法如何解决这个问题?我在 IISExpress 下的本地机器上运行它。

blazor.server.js:1 [2020-01-22T08:08:24.333Z] Information: Normalizing '_blazor' to 'https://localhost:44347/UserManagement/_blazor'.
blazor.server.js:1 [2020-01-22T08:08:24.845Z] Information: WebSocket connected to wss://localhost:44347/UserManagement/_blazor?id=SDcEnRoqVlu-3GRhPqRj7g.
blazor.server.js:15 [2020-01-22T08:08:25.064Z] Error: The circuit failed to initialize.
e.log @ blazor.server.js:15
C @ blazor.server.js:8
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.invokeClientMethod @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
blazor.server.js:1 [2020-01-22T08:08:25.067Z] Information: Connection disconnected.
blazor.server.js:1 Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
    at e.connectionClosed (blazor.server.js:1)
    at e.connection.onclose (blazor.server.js:1)
    at e.stopConnection (blazor.server.js:1)
    at e.transport.onclose (blazor.server.js:1)
    at e.close (blazor.server.js:1)
    at e.stop (blazor.server.js:1)
    at e.<anonymous> (blazor.server.js:1)
    at blazor.server.js:1
    at Object.next (blazor.server.js:1)
    at a (blazor.server.js:1)
e.connectionClosed @ blazor.server.js:1
connection.onclose @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:8
a @ blazor.server.js:8
Promise.then (async)
c @ blazor.server.js:8
(anonymous) @ blazor.server.js:8
r @ blazor.server.js:8
E @ blazor.server.js:8
(anonymous) @ blazor.server.js:8
n @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1

我的 Startup.cs 如下所示:

    using Blazored.Modal;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using UserManagement.Data;
    using UserManagement.Models;

    namespace UserManagement
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }

            public IConfiguration Configuration { get; }

            // This method gets called by the runtime. Use this method to add services to the container.
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddRazorPages();
                services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
                services.AddBlazoredModal();
                services.AddDbContext<UserManagementContext>(options => options.UseSqlServer(REMOVED);
                services.AddDbContext<RecertificationContext>(options => options.UseSqlServer(REMOVED);

                var config = new ConfigurationBuilder()
                    .Build();
                services.AddSingleton(config);
            }

            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                app.UsePathBase("/UserManagement");
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                    app.UseHsts();
                }

                app.UseHttpsRedirection();
                app.UseStaticFiles();            

                app.UseRouting();

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapBlazorHub();
                    endpoints.MapFallbackToPage("/_Host");
                });
            }


  }
}

_Host.cshtml

@page "/"
@namespace UserManagement.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>UserManagement</title>
    <environment include="Development">
        <base href="/UserManagement/" />
    </environment>
    <environment exclude="Development">
        <base href="~/" />
    </environment>
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="_content/Blazored.Typeahead/blazored-typeahead.css" rel="stylesheet" />
    <link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
</head>
<body>
    <app>
        @(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))
    </app>

    <script src="_framework/blazor.server.js"></script>
    <script src="_content/Blazored.Typeahead/blazored-typeahead.js"></script>
    <script src="_content/BlazorFileSaver/BlazorFileSaver.min.js"></script>
</body>
</html>

【问题讨论】:

  • 不要使用屏幕截图,而是复制异常文本并“引用”它。对我来说,只有 @page 指令的空 Index.razor 一切正常。
  • 你在你的 startup.cs 中加载了什么?任何可能导致崩溃的服务?
  • 已将我的创业公司添加到最初的问题中。

标签: blazor blazor-server-side


【解决方案1】:

这很有趣。我创建了一个新的 Blazor 服务器端项目并将我的所有类复制到该项目中,并确保两个项目中的代码相同。你猜怎么着,这个错误并没有出现在新项目中。

除了清理/重建项目之外,有没有办法“擦除”某种缓存?

【讨论】:

  • 只是好奇,我对 blazor 也有同样的问题。您的“新”项目是否也更改了基本 href?
猜你喜欢
  • 1970-01-01
  • 2021-08-06
  • 2017-04-29
  • 1970-01-01
  • 1970-01-01
  • 2011-03-06
  • 1970-01-01
  • 2020-12-10
  • 1970-01-01
相关资源
最近更新 更多