本文介绍了随机“错误:电路初始化失败".与Blazor应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently developing a Blazor server side app and I am experiencing a random error directly after starting the page. When I hit the F5-button or click any link on my index page, the page is reloaded and the error does not appear again. The error message is very generic and I really don't know where to start to debug this. The error occurs even when I entirely remove the content of my Index.razor page, which is the starting page. Any ideas how to approach this problem? I'm running this on my local machine under 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看起来像这样:

My Startup.cs looks like this:

    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

_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>

推荐答案

这很有趣.我创建了一个新的Blazor服务器端项目,并将所有类复制到该项目中,并确保两个项目中的代码相同.并猜测是什么,该错误不会出现在新项目中.

It's interesting. I created a new Blazor server-side project and copied all my classes to this project and made sure that the code is identical in both projects. And guess what, the error does not appear in the new project.

除了清除/重建项目外,还有什么方法可以擦除"某种缓存吗?

Is there any way to "erase" some kind of cache that goes beyond clean/rebuild of a project?

这篇关于随机“错误:电路初始化失败".与Blazor应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:03