自从升级到Net Core 3.0 Preview 9
我在尝试注入我的控制台记录器时遇到以下错误;
WASM:System.MissingMethodException:找不到方法:System.Threading.Tasks.Task`1 Microsoft.JSInterop.IJSRuntime.InvokeAsync(string,object[])
WASM:在 System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) <0x2df6378 + 0x0003e> in :0
WASM:在 Blazor.Extensions.Logging.BrowserConsoleLogger.Log[TState](Microsoft.Extensions.Logging.LogLevel logLevel,Microsoft.Extensions.Logging.EventId eventId,TState 状态,System.Exception 异常,System.Func`3[T1, T2,TResult] 格式化程序) <0x2df5e90 + 0x00094> 在 <3eb34b93cd4a47bf804fb0648b089edf>:0
WASM:在 Microsoft.Extensions.Logging.LoggerMessage+<>c__DisplayClass4_0.b__0(Microsoft.Extensions.Logging.ILogger 记录器,System.Exception 异常)<0x2df51a0 + 0x00058> 在:0
WASM:在(包装器委托调用)System.Action`2[Microsoft.Extensions.Logging.ILogger,System.Exception].invoke_void_T1_T2(Microsoft.Extensions.Logging.ILogger,System.Exception)
WASM:在 Microsoft.Extensions.Logging.LoggingExtensions.UserAuthorizationFailed (Microsoft.Extensions.Logging.ILogger 记录器) <0x2dee5f0 + 0x00014> 在 <85acc2b572f448f39259eac9936732f8>:0
WASM:在 Microsoft.AspNetCore.Authorization.DefaultAuthorizationService.AuthorizeAsync(System.Security.Claims.ClaimsPrincipal 用户,System.Object 资源,System.Collections.Generic.IEnumerable`1[T] 要求)<85acc2b572f448f39259eac9936732f8> 中的 <0x2ddd378 + 0x00338> :0
WASM:在 Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.IsAuthorizedAsync (System.Security.Claims.ClaimsPrincipal 用户) <0x2d52860 + 0x00228> 在 <5266bbb196bb40a89b886a09631725e6>:0
WASM:在 Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync () <0x2d512a0 + 0x0026c> 在 <5266bbb196bb40a89b886a09631725e6>:0
WASM:在 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(System.Threading.Tasks.Task 任务)<0x2e0b8f0 + 0x00118> 中:0
WASM:在 Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2bbb2e8 + 0x00248> in :0
在我的剃刀视图中,我按如下方式注入记录器;
@inject ILogger<Index> logger
我的基础_Imports.razor
如下;
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Authorization
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.JSInterop
@using Microsoft.Extensions.Logging
@using Blazored.LocalStorage
@using Blazorise
@using Blazorise.Sidebar
我App.razor
的是;
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<p>Nope, nope!</p>
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
现在正在渲染的视图是一个登录页面。如果用户未获得授权,则会在重定向时移至该位置。所以在我的MainLayout.Razor
页面中,我有以下内容;
@functions
{
[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; }
protected override async Task OnInitializedAsync()
{
var authState = await authenticationStateTask;
var user = authState.User;
if (!user.Identity.IsAuthenticated)
{
UriHelper.NavigateTo(@"\login");
}
}
}
为了完整起见ConfigureServices
,我的Startup.cs
添加记录器如下;
services.AddLogging(builder => builder
.AddBrowserConsole()
.SetMinimumLevel(LogLevel.Trace)
);
谁能告诉我我在这里做错了什么?由于“登录”页面正在呈现,它似乎只是问题所在的记录器?
Per Tsengs 评论我的 nuget 依赖项如下;