Blazorstrap 不适用于 .NET 6 Blazor?
Blazorstrap not working for .NET 6 Blazor?
我是 Blazor 的新手,正在试用 .NET 6.0 中的 Blazor。
我创建了默认的 Blazor Server App 项目并按照 Blazorstrap 网站(版本 5)上的说明进行操作
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddBlazorStrap();
builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();
我添加了服务、导入和网页行,它构建良好。
但是,当我启动项目时,出现以下错误
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BlazorStrap.Utilities.ISvgLoader Lifetime: Scoped ImplementationType: BlazorStrap.Utilities.SvgLoader': Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'BlazorStrap.Utilities.SvgLoader'.)'
Blazorstrap 不适用于 .NET 6 吗?还是我没有设置?
我是一个完全的 Blazor 新手,所以任何帮助将不胜感激。
像这样添加 HttpClient 服务对我有用。
if (!builder.Services.Any(x => x.ServiceType == typeof(HttpClient)))
{
// Setup HttpClient for server side in a client side compatible fashion
builder.Services.AddScoped<HttpClient>(s =>
{
// Creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
NavigationManager navman = s.GetRequiredService<NavigationManager>();
return new HttpClient
{
BaseAddress = new Uri(navman.BaseUri)
};
});
}
builder.Services.AddBlazorStrap();
默认情况下,Blazor 服务器不会在 HttpClient 中加载。 SvgLoader 依赖于它。这就是为什么你得到错误。这将在下一个版本中解决。
根据您的模板将 blazor_guest 发布的内容添加到您的 startup.cs 或 program.cs 将解决问题。
我是 Blazor 的新手,正在试用 .NET 6.0 中的 Blazor。
我创建了默认的 Blazor Server App 项目并按照 Blazorstrap 网站(版本 5)上的说明进行操作
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddBlazorStrap();
builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();
我添加了服务、导入和网页行,它构建良好。
但是,当我启动项目时,出现以下错误
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BlazorStrap.Utilities.ISvgLoader Lifetime: Scoped ImplementationType: BlazorStrap.Utilities.SvgLoader': Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'BlazorStrap.Utilities.SvgLoader'.)'
Blazorstrap 不适用于 .NET 6 吗?还是我没有设置?
我是一个完全的 Blazor 新手,所以任何帮助将不胜感激。
像这样添加 HttpClient 服务对我有用。
if (!builder.Services.Any(x => x.ServiceType == typeof(HttpClient)))
{
// Setup HttpClient for server side in a client side compatible fashion
builder.Services.AddScoped<HttpClient>(s =>
{
// Creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
NavigationManager navman = s.GetRequiredService<NavigationManager>();
return new HttpClient
{
BaseAddress = new Uri(navman.BaseUri)
};
});
}
builder.Services.AddBlazorStrap();
默认情况下,Blazor 服务器不会在 HttpClient 中加载。 SvgLoader 依赖于它。这就是为什么你得到错误。这将在下一个版本中解决。 根据您的模板将 blazor_guest 发布的内容添加到您的 startup.cs 或 program.cs 将解决问题。