diff --git a/eng/TrimmableProjects.props b/eng/TrimmableProjects.props
index 905704f83866..50a1520c5757 100644
--- a/eng/TrimmableProjects.props
+++ b/eng/TrimmableProjects.props
@@ -31,6 +31,9 @@
+
+
+
@@ -88,6 +91,7 @@
+
diff --git a/src/Identity/Core/src/IdentityBuilderExtensions.cs b/src/Identity/Core/src/IdentityBuilderExtensions.cs
index 7f98ca8d2e60..a05ca35c002c 100644
--- a/src/Identity/Core/src/IdentityBuilderExtensions.cs
+++ b/src/Identity/Core/src/IdentityBuilderExtensions.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Identity;
@@ -55,7 +56,7 @@ public static IdentityBuilder AddSignInManager(this IdentityBuilder builder)
/// The type of the sign in manager to add.
/// The current instance.
/// The current instance.
- public static IdentityBuilder AddSignInManager(this IdentityBuilder builder) where TSignInManager : class
+ public static IdentityBuilder AddSignInManager<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TSignInManager>(this IdentityBuilder builder) where TSignInManager : class
{
builder.AddSignInManagerDeps();
var managerType = typeof(SignInManager<>).MakeGenericType(builder.UserType);
diff --git a/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs b/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs
index 25ac9c490764..5cf717b3c3c9 100644
--- a/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs
+++ b/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
@@ -20,7 +21,7 @@ public static class IdentityServiceCollectionExtensions
/// The type representing a Role in the system.
/// The services available in the application.
/// An for creating and configuring the identity system.
- public static IdentityBuilder AddIdentity(
+ public static IdentityBuilder AddIdentity(
this IServiceCollection services)
where TUser : class
where TRole : class
@@ -34,7 +35,7 @@ public static IdentityBuilder AddIdentity(
/// The services available in the application.
/// An action to configure the .
/// An for creating and configuring the identity system.
- public static IdentityBuilder AddIdentity(
+ public static IdentityBuilder AddIdentity(
this IServiceCollection services,
Action setupAction)
where TUser : class
diff --git a/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj b/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj
index e021c9b31e71..052f8efcc524 100644
--- a/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj
+++ b/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj
@@ -7,11 +7,15 @@
true
aspnetcore;identity;membership
false
+ true
+
+
diff --git a/src/Identity/EntityFrameworkCore/src/UserStore.cs b/src/Identity/EntityFrameworkCore/src/UserStore.cs
index fb5d7c90a4f7..e13662f26fb3 100644
--- a/src/Identity/EntityFrameworkCore/src/UserStore.cs
+++ b/src/Identity/EntityFrameworkCore/src/UserStore.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Security.Claims;
@@ -89,7 +90,7 @@ public UserStore(TContext context, IdentityErrorDescriber? describer = null) : b
/// The type representing a user external login.
/// The type representing a user token.
/// The type representing a role claim.
-public class UserStore :
+public class UserStore :
UserStoreBase,
IProtectedUserStore
where TUser : IdentityUser
diff --git a/src/Identity/Extensions.Core/src/IdentityBuilder.cs b/src/Identity/Extensions.Core/src/IdentityBuilder.cs
index c22746ba9075..28e3804e9c93 100644
--- a/src/Identity/Extensions.Core/src/IdentityBuilder.cs
+++ b/src/Identity/Extensions.Core/src/IdentityBuilder.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
+using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Identity.Core;
@@ -30,7 +31,7 @@ public IdentityBuilder(Type user, IServiceCollection services)
/// The to use for the users.
/// The to use for the roles.
/// The to attach to.
- public IdentityBuilder(Type user, Type role, IServiceCollection services) : this(user, services)
+ public IdentityBuilder(Type user, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type role, IServiceCollection services) : this(user, services)
=> RoleType = role;
///
@@ -47,6 +48,7 @@ public IdentityBuilder(Type user, Type role, IServiceCollection services) : this
///
/// The used for roles.
///
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
public Type? RoleType { get; private set; }
///
@@ -57,7 +59,7 @@ public IdentityBuilder(Type user, Type role, IServiceCollection services) : this
///
public IServiceCollection Services { get; }
- private IdentityBuilder AddScoped(Type serviceType, Type concreteType)
+ private IdentityBuilder AddScoped(Type serviceType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type concreteType)
{
Services.AddScoped(serviceType, concreteType);
return this;
@@ -68,7 +70,7 @@ private IdentityBuilder AddScoped(Type serviceType, Type concreteType)
///
/// The user validator type.
/// The current instance.
- public virtual IdentityBuilder AddUserValidator() where TValidator : class
+ public virtual IdentityBuilder AddUserValidator<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TValidator>() where TValidator : class
=> AddScoped(typeof(IUserValidator<>).MakeGenericType(UserType), typeof(TValidator));
///
@@ -76,7 +78,7 @@ public virtual IdentityBuilder AddUserValidator() where TValidator :
///
/// The type of the claims principal factory.
/// The current instance.
- public virtual IdentityBuilder AddClaimsPrincipalFactory() where TFactory : class
+ public virtual IdentityBuilder AddClaimsPrincipalFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TFactory>() where TFactory : class
=> AddScoped(typeof(IUserClaimsPrincipalFactory<>).MakeGenericType(UserType), typeof(TFactory));
///
@@ -84,7 +86,7 @@ public virtual IdentityBuilder AddClaimsPrincipalFactory() where TFact
///
/// The type of the error describer.
/// The current instance.
- public virtual IdentityBuilder AddErrorDescriber() where TDescriber : IdentityErrorDescriber
+ public virtual IdentityBuilder AddErrorDescriber<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TDescriber>() where TDescriber : IdentityErrorDescriber
{
Services.AddScoped();
return this;
@@ -95,7 +97,7 @@ public virtual IdentityBuilder AddErrorDescriber() where TDescriber
///
/// The validator type used to validate passwords.
/// The current instance.
- public virtual IdentityBuilder AddPasswordValidator() where TValidator : class
+ public virtual IdentityBuilder AddPasswordValidator<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TValidator>() where TValidator : class
=> AddScoped(typeof(IPasswordValidator<>).MakeGenericType(UserType), typeof(TValidator));
///
@@ -103,7 +105,7 @@ public virtual IdentityBuilder AddPasswordValidator() where TValidat
///
/// The user store type.
/// The current instance.
- public virtual IdentityBuilder AddUserStore() where TStore : class
+ public virtual IdentityBuilder AddUserStore<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TStore>() where TStore : class
=> AddScoped(typeof(IUserStore<>).MakeGenericType(UserType), typeof(TStore));
///
@@ -112,7 +114,7 @@ public virtual IdentityBuilder AddUserStore() where TStore : class
/// The type of the token provider to add.
/// The name of the provider to add.
/// The current instance.
- public virtual IdentityBuilder AddTokenProvider(string providerName) where TProvider : class
+ public virtual IdentityBuilder AddTokenProvider<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>(string providerName) where TProvider : class
=> AddTokenProvider(providerName, typeof(TProvider));
///
@@ -121,7 +123,7 @@ public virtual IdentityBuilder AddTokenProvider(string providerName)
/// The name of the provider to add.
/// The type of the to add.
/// The current instance.
- public virtual IdentityBuilder AddTokenProvider(string providerName, Type provider)
+ public virtual IdentityBuilder AddTokenProvider(string providerName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type provider)
{
if (!typeof(IUserTwoFactorTokenProvider<>).MakeGenericType(UserType).IsAssignableFrom(provider))
{
@@ -140,7 +142,7 @@ public virtual IdentityBuilder AddTokenProvider(string providerName, Type provid
///
/// The type of the user manager to add.
/// The current instance.
- public virtual IdentityBuilder AddUserManager() where TUserManager : class
+ public virtual IdentityBuilder AddUserManager<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TUserManager>() where TUserManager : class
{
var userManagerType = typeof(UserManager<>).MakeGenericType(UserType);
var customType = typeof(TUserManager);
@@ -160,7 +162,7 @@ public virtual IdentityBuilder AddUserManager() where TUserManager
///
/// The role type.
/// The current instance.
- public virtual IdentityBuilder AddRoles() where TRole : class
+ public virtual IdentityBuilder AddRoles<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TRole>() where TRole : class
{
RoleType = typeof(TRole);
AddRoleValidator>();
@@ -174,7 +176,7 @@ public virtual IdentityBuilder AddRoles() where TRole : class
///
/// The role validator type.
/// The current instance.
- public virtual IdentityBuilder AddRoleValidator() where TRole : class
+ public virtual IdentityBuilder AddRoleValidator<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TRole>() where TRole : class
{
if (RoleType == null)
{
@@ -189,7 +191,7 @@ public virtual IdentityBuilder AddRoleValidator() where TRole : class
/// The personal data protector type.
/// The personal data protector key ring type.
/// The current instance.
- public virtual IdentityBuilder AddPersonalDataProtection()
+ public virtual IdentityBuilder AddPersonalDataProtection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProtector, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TKeyRing>()
where TProtector : class, ILookupProtector
where TKeyRing : class, ILookupProtectorKeyRing
{
@@ -204,7 +206,7 @@ public virtual IdentityBuilder AddPersonalDataProtection()
///
/// The role store.
/// The current instance.
- public virtual IdentityBuilder AddRoleStore() where TStore : class
+ public virtual IdentityBuilder AddRoleStore<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TStore>() where TStore : class
{
if (RoleType == null)
{
@@ -218,7 +220,7 @@ public virtual IdentityBuilder AddRoleStore() where TStore : class
///
/// The type of the role manager to add.
/// The current instance.
- public virtual IdentityBuilder AddRoleManager() where TRoleManager : class
+ public virtual IdentityBuilder AddRoleManager<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TRoleManager>() where TRoleManager : class
{
if (RoleType == null)
{
@@ -242,6 +244,6 @@ public virtual IdentityBuilder AddRoleManager() where TRoleManager
///
/// The type of the user confirmation to add.
/// The current instance.
- public virtual IdentityBuilder AddUserConfirmation() where TUserConfirmation : class
+ public virtual IdentityBuilder AddUserConfirmation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TUserConfirmation>() where TUserConfirmation : class
=> AddScoped(typeof(IUserConfirmation<>).MakeGenericType(UserType), typeof(TUserConfirmation));
}
diff --git a/src/Identity/Extensions.Core/src/Microsoft.Extensions.Identity.Core.csproj b/src/Identity/Extensions.Core/src/Microsoft.Extensions.Identity.Core.csproj
index b47766eb7915..f0ab95bac40c 100644
--- a/src/Identity/Extensions.Core/src/Microsoft.Extensions.Identity.Core.csproj
+++ b/src/Identity/Extensions.Core/src/Microsoft.Extensions.Identity.Core.csproj
@@ -1,4 +1,4 @@
-
+
ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. ASP.NET Core Identity allows you to add login features to your application and makes it easy to customize data about the logged in user.
@@ -7,12 +7,16 @@
true
true
aspnetcore;identity;membership
+ true
+
+
true
true
aspnetcore;identity;membership
+ true
+
+
diff --git a/src/Identity/Extensions.Stores/src/RoleStoreBase.cs b/src/Identity/Extensions.Stores/src/RoleStoreBase.cs
index d80e61d02034..59c0f3176bd3 100644
--- a/src/Identity/Extensions.Stores/src/RoleStoreBase.cs
+++ b/src/Identity/Extensions.Stores/src/RoleStoreBase.cs
@@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Identity;
/// The type of the primary key for a role.
/// The type of the class representing a user role.
/// The type of the class representing a role claim.
-public abstract class RoleStoreBase :
+public abstract class RoleStoreBase :
IQueryableRoleStore,
IRoleClaimStore
where TRole : IdentityRole
@@ -130,6 +130,8 @@ public RoleStoreBase(IdentityErrorDescriber describer)
///
/// The id to convert.
/// An instance of representing the provided .
+ [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
+ Justification = "TKey is annoated with RequiresUnreferencedCodeAttribute.All.")]
public virtual TKey? ConvertIdFromString(string? id)
{
if (id == null)
diff --git a/src/Identity/Extensions.Stores/src/UserStoreBase.cs b/src/Identity/Extensions.Stores/src/UserStoreBase.cs
index 1277ee06bb07..7eb2173358ae 100644
--- a/src/Identity/Extensions.Stores/src/UserStoreBase.cs
+++ b/src/Identity/Extensions.Stores/src/UserStoreBase.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Identity;
/// The type representing a claim.
/// The type representing a user external login.
/// The type representing a user token.
-public abstract class UserStoreBase :
+public abstract class UserStoreBase :
IUserLoginStore,
IUserClaimStore,
IUserPasswordStore,
@@ -237,6 +237,8 @@ protected virtual TUserToken CreateUserToken(TUser user, string loginProvider, s
///
/// The id to convert.
/// An instance of representing the provided .
+ [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
+ Justification = "TKey is annoated with RequiresUnreferencedCodeAttribute.All.")]
public virtual TKey? ConvertIdFromString(string? id)
{
if (id == null)
@@ -1085,7 +1087,7 @@ public virtual async Task RedeemCodeAsync(TUser user, string code, Cancell
/// The type representing a user external login.
/// The type representing a user token.
/// The type representing a role claim.
-public abstract class UserStoreBase :
+public abstract class UserStoreBase :
UserStoreBase,
IUserRoleStore
where TUser : IdentityUser
diff --git a/src/Localization/Abstractions/src/Microsoft.Extensions.Localization.Abstractions.csproj b/src/Localization/Abstractions/src/Microsoft.Extensions.Localization.Abstractions.csproj
index ac1da8c6f66b..d9945fec8dd6 100644
--- a/src/Localization/Abstractions/src/Microsoft.Extensions.Localization.Abstractions.csproj
+++ b/src/Localization/Abstractions/src/Microsoft.Extensions.Localization.Abstractions.csproj
@@ -1,4 +1,4 @@
-
+
Microsoft .NET Extensions
@@ -12,6 +12,7 @@ Microsoft.Extensions.Localization.IStringLocalizer<T>
localization
true
enable
+ true
diff --git a/src/Tools/Tools.slnf b/src/Tools/Tools.slnf
index 422aee5e931c..096ec397aa19 100644
--- a/src/Tools/Tools.slnf
+++ b/src/Tools/Tools.slnf
@@ -38,7 +38,11 @@
"src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj",
"src\\Http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj",
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
+ "src\\Identity\\Core\\src\\Microsoft.AspNetCore.Identity.csproj",
+ "src\\Identity\\Extensions.Core\\src\\Microsoft.Extensions.Identity.Core.csproj",
+ "src\\Identity\\Extensions.Stores\\src\\Microsoft.Extensions.Identity.Stores.csproj",
"src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj",
+ "src\\Localization\\Abstractions\\src\\Microsoft.Extensions.Localization.Abstractions.csproj",
"src\\Middleware\\CORS\\src\\Microsoft.AspNetCore.Cors.csproj",
"src\\Middleware\\ConcurrencyLimiter\\src\\Microsoft.AspNetCore.ConcurrencyLimiter.csproj",
"src\\Middleware\\Diagnostics.Abstractions\\src\\Microsoft.AspNetCore.Diagnostics.Abstractions.csproj",