dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.59k stars 10.06k forks source link

System.TypeLoadException Could not load type Microsoft.AspNetCore.Identity.UI.Services.IEmailSender #51319

Closed wa1gon closed 1 year ago

wa1gon commented 1 year ago

Description

I updated VS 2022 to 17.8.0 Preview 3 and two applications that I have been working on started to throw the same exception:

System.TypeLoadException HResult=0x80131522 Message=Could not load type 'Microsoft.AspNetCore.Identity.UI.Services.IEmailSender' from assembly 'Microsoft.Extensions.Identity.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Source=Microsoft.AspNetCore.Identity.UI StackTrace: at Microsoft.AspNetCore.Identity.IdentityBuilderUIExtensions.AddDefaultUI(IdentityBuilder builder) at Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionUIExtensions.AddDefaultIdentity[TUser](IServiceCollection services, Action`1 configureOptions) at Program.

$(String[] args) in C:\github\laurelwww\Laurel_site\Program.cs:line 12

This was working in RC1

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? 
    throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<AmateurUserDbContext>(options =>
    options.UseSqlite(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<AmateurUser>(options => options.SignIn.RequireConfirmedAccount = true)
    .AddRoles<IdentityRole>()
    .AddEntityFrameworkStores<AmateurUserDbContext>();

Configuration

.NET Version .NET8 RC2 OS: Windows 11 Architecture: X64 Identity Database: SQLite Configuration has changed. Just upgraded to the latest VS It is a Blazor Server app, but it's not making it through injected services

Regression?

It did work on the last RC, but when I updated it, it started throwing exceptions.

Other information

Kahbazi commented 1 year ago

@wa1gon Could you please also share the Microsoft nuget packages that is installed on your project? I'm guessing maybe theses two packages are not updated to v8.0. Microsoft.Extensions.Identity.Core and Microsoft.AspNetCore.Identity.UI

martinalderson commented 1 year ago

Also experienced this; needed to update identity ui package from rc1 to rc2. Are these breaking changes like this meant to happen with rc builds? I was of the understanding they should be more stable than this. We have moved more aggressively to net8 because of various features which are a huge help to our project, normally we would wait for the final release so I am not entirely sure of how much things should break release to release in the rc phase.

Question though, is there some way to 'pin' the rc we are using in docker? The issue is that the 8.0.0 tag on docker points to the latest rc, which as exposed here can require nuget package updates. We would prefer to use a specific version and update nugets and docker images at the same time.

I tried

FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-rc.2 AS base

but this file can't be found.

EDIT: it's because of the sdk reference which needs to be 8.1.00-rc2, not 8.0.0-rc2 as i had

wa1gon commented 1 year ago

It seems like everything is rc1, however this happen using 2022 preview 3.

<PackageReference Include="Dapper" Version="2.0.151" />
    <PackageReference Include="Mailjet.Api" Version="3.0.0" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.1" />
    <PackageReference Include="what3words.dotnet.wrapper" Version="3.0.5" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0-rc.1.23421.29" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0-rc.1.23421.29" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0-rc.1.23421.29" />
    <PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0-rc.1.23419.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-rc.1.23419.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.0-rc.1.23419.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-rc.1.23419.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0-rc.1.23419.6" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0-rc.1.23461.3" />
wa1gon commented 1 year ago

The solution was to go into NuGet package manager and do the updates for rc2. Be sure to check the preview at the top.

wa1gon commented 1 year ago

Yes, when into the solution nuget and did an update. Don't forget to check preview on the nuget.

On Sat, Oct 14, 2023 at 10:27 AM luis cañas @.***> wrote:

i have the same issue on rc2, did you solve it?

— Reply to this email directly, view it on GitHub https://github.com/dotnet/aspnetcore/issues/51319#issuecomment-1762966471, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMEW3Z67VOW4XYXDPSDJFDX7KVOJANCNFSM6AAAAAA55LPPSI . You are receiving this because you were mentioned.Message ID: @.***>

SrknMcT commented 1 year ago

No , it is not the solution in my case .

Identity packages' version: 8.0.0-rc.2.23480.2 and EntityFramework packages' version : 8.0.0-rc.2.23480.1, no way still same error.

SrknMcT commented 1 year ago

The problem occured while trying to update all packages to the latest version.And after that I realized that Identity packages' versions a bit ahead than others so I solved with downgrading Identity based packages to rc.1.23421.29 and keeping other EntityFramework packages at latest version.

schorges commented 1 year ago

The problem occured while trying to update all packages to the latest version.And after that I realized that Identity packages' versions a bit ahead than others so I solved with downgrading Identity based packages to rc.1.23421.29 and keeping other EntityFramework packages at latest version.

Install all to 8.0.0.-rc.1.23421.29 or rc2 ***** not work, in my case i install and deinstall and wondering the Version 8.0.0 is released today - 14.11.2023 after Change the Microsoft.AspNetCore.Identity.UI to 8.0.0 it work's fine! Also work on have other packes in rc1 or rc2.

ccirbista commented 11 months ago

I am getting this exception when trying to run my application after scaffolding the identity into the project. dotNet8Exception