Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Error cast object of type in Blazor server app on .NET 6 session

$
0
0

I'm using Entity Framework Core to validate the user and password from the database, but when I try to declare a var authenticationExt using polymorphism because the class inherited from authenticationProvider, the debugger says:

System.InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider' to type 'Blazor_Server_App_Login.Extensions.AuthenticationExt'

I extracted this same code from a project in .NET 7. Any suggestions?

@page "/"@layout LoginLayout@inject HttpClient httpClient@using Blazor_Server_App_Login.Extensions@using Blazor_Server_App_Login.Shared@using Blazor_Server_App_Login.Login@using Microsoft.AspNetCore.Components.Authorization@inject AuthenticationStateProvider authenticationProvider@inject NavigationManager navManager<div class="row mt-5"><div class="col-lg-4 offset-lg-4 border"><div class="mb-3 text-center"><h3>LOGIN</h3></div><div class="mb-3"><label>Email</label><input @bind="login.email" class="form-control" /></div><div class="mb-3"><label>Password</label><input @bind="login.password" class="form-control" /></div><div class="mb-3"><button @onclick="IniciarSesion" class="btn btn-primary">Login</button></div></div></div>@code {    private UserLogin login = new UserLogin();    private async Task IniciarSesion()    {        var loginResponse = await httpClient.PostAsJsonAsync<UserLogin>("https://localhost:7146/api/User/Login", login);        if (loginResponse.IsSuccessStatusCode)        {            // AuthenticationStateProvider i = new AuthenticationExt();            var sesionUser = await loginResponse.Content.ReadFromJsonAsync<SessionState>();            var autenticationExt = (AuthenticationExt)authenticationProvider;            await autenticationExt.UdateAuthState(sesionUser);            navManager.NavigateTo("/Index");        }    }}

Full code at: https://github.com/bonfildev/Blazor-Server-App-Login


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>