问题
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
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
@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>
回答1:
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?
来源:https://stackoverflow.com/questions/59837098/random-error-the-circuit-failed-to-initialize-with-blazor-app