【发布时间】:2019-09-10 08:00:08
【问题描述】:
自从升级到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) 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] 格式化程序) in :0
WASM:在 Microsoft.Extensions.Logging.LoggerMessage+c__DisplayClass4_0.b__0(Microsoft.Extensions.Logging.ILogger 记录器,System.Exception 异常) 在: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 记录器) 在 :0
WASM:在 Microsoft.AspNetCore.Authorization.DefaultAuthorizationService.AuthorizeAsync(System.Security.Claims.ClaimsPrincipal 用户,System.Object 资源,System.Collections.Generic.IEnumerable`1[T] 要求) 中:0
WASM:在 Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.IsAuthorizedAsync(System.Security.Claims.ClaimsPrincipal 用户) 在 :0
WASM: 在 Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync () in :0
WASM:在 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(System.Threading.Tasks.Task 任务) 中:0
WASM: 在 Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () 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");
}
}
}
为了完整起见,我的Startup.cs 中的ConfigureServices 添加了如下记录器;
services.AddLogging(builder => builder
.AddBrowserConsole()
.SetMinimumLevel(LogLevel.Trace)
);
谁能告诉我我在这里做错了什么?由于“登录”页面正在呈现,它似乎只是问题所在的记录器?
Per Tsengs 评论我的 nuget 依赖项如下;
【问题讨论】:
-
如果禁用链接器还会出现这种情况吗?
-
确认一下,我刚刚尝试过,是的,它仍然会在链接器禁用的情况下发生
标签: c# asp.net-core blazor blazor-client-side