diff --git a/src/Components/WebAssembly/Sdk/integrationtests/WasmPublishIntegrationTest.cs b/src/Components/WebAssembly/Sdk/integrationtests/WasmPublishIntegrationTest.cs
index 909a71c52917..e29a31909270 100644
--- a/src/Components/WebAssembly/Sdk/integrationtests/WasmPublishIntegrationTest.cs
+++ b/src/Components/WebAssembly/Sdk/integrationtests/WasmPublishIntegrationTest.cs
@@ -141,8 +141,6 @@ public async Task Publish_WithScopedCss_Works()
serviceWorkerPath: Path.Combine("serviceworkers", "my-service-worker.js"),
serviceWorkerContent: "// This is the production service worker",
assetsManifestPath: "custom-service-worker-assets.js");
-
- VerifyTypeGranularTrimming(result, blazorPublishDirectory);
}
[Fact]
@@ -906,16 +904,17 @@ static string ParseWebFormattedHash(string webFormattedHash)
private void VerifyTypeGranularTrimming(MSBuildResult result, string blazorPublishDirectory)
{
- var loggingAssemblyPath = Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.Extensions.Logging.Abstractions.dll");
- Assert.FileExists(result, loggingAssemblyPath);
+ var componentsShimAssemblyPath = Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.AspNetCore.Razor.Test.ComponentShim.dll");
+ Assert.FileExists(result, componentsShimAssemblyPath);
+
+ // RouteView is referenced by the app, so we expect it to be preserved
+ Assert.AssemblyContainsType(result, componentsShimAssemblyPath, "Microsoft.AspNetCore.Components.RouteView");
- // ILogger is referenced by the app, so we expect it to be preserved
- Assert.AssemblyContainsType(result, loggingAssemblyPath, "Microsoft.Extensions.Logging.ILogger");
- // LogLevel is referenced by ILogger and therefore must be preserved.
- Assert.AssemblyContainsType(result, loggingAssemblyPath, "Microsoft.Extensions.Logging.LogLevel");
+ // RouteData is referenced by RouteView so we expect it to be preserved.
+ Assert.AssemblyContainsType(result, componentsShimAssemblyPath, "Microsoft.AspNetCore.Components.RouteData");
- // NullLogger is not referenced by the app, and should be trimmed.
- Assert.AssemblyDoesNotContainType(result, loggingAssemblyPath, "Microsoft.Extensions.Logging.Abstractions.NullLogger");
+ // CascadingParameterAttribute is not referenced by the app, and should be trimmed.
+ Assert.AssemblyDoesNotContainType(result, componentsShimAssemblyPath, "Microsoft.AspNetCore.Components.CascadingParameterAttribute");
}
private static BootJsonData ReadBootJsonData(MSBuildResult result, string path)
diff --git a/src/Components/WebAssembly/Sdk/src/targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets b/src/Components/WebAssembly/Sdk/src/targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets
index 370d535eefe3..13982d548aee 100644
--- a/src/Components/WebAssembly/Sdk/src/targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets
+++ b/src/Components/WebAssembly/Sdk/src/targets/Microsoft.NET.Sdk.BlazorWebAssembly.Current.targets
@@ -69,6 +69,12 @@ Copyright (c) .NET Foundation. All rights reserved.
+
+
+
+
+
+
@@ -395,7 +401,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<_BlazorTypeGranularAssembly
Include="@(ManagedAssemblyToLink)"
- Condition="'%(Extension)' == '.dll' AND ($([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.')) or $([System.String]::Copy('%(Filename)').StartsWith('Microsoft.Extensions.')))">
+ Condition="'%(Extension)' == '.dll' AND $([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.'))">
false
all
diff --git a/src/Components/WebAssembly/Sdk/testassets/blazorwasm/Program.cs b/src/Components/WebAssembly/Sdk/testassets/blazorwasm/Program.cs
index 0784957affba..4b20dea9ded0 100644
--- a/src/Components/WebAssembly/Sdk/testassets/blazorwasm/Program.cs
+++ b/src/Components/WebAssembly/Sdk/testassets/blazorwasm/Program.cs
@@ -8,7 +8,6 @@ public static void Main(string[] args)
{
GC.KeepAlive(typeof(System.Text.Json.JsonSerializer));
GC.KeepAlive(typeof(RazorClassLibrary.Class1));
- GC.KeepAlive(typeof(Microsoft.Extensions.Logging.ILogger));
#if REFERENCE_classlibrarywithsatelliteassemblies
GC.KeepAlive(typeof(classlibrarywithsatelliteassemblies.Class1));
#endif
diff --git a/src/FileProviders/Embedded/src/Manifest/ManifestDirectory.cs b/src/FileProviders/Embedded/src/Manifest/ManifestDirectory.cs
index b75653a0fb0f..3aa2429ad6dd 100644
--- a/src/FileProviders/Embedded/src/Manifest/ManifestDirectory.cs
+++ b/src/FileProviders/Embedded/src/Manifest/ManifestDirectory.cs
@@ -98,7 +98,7 @@ internal static void ValidateChildrenAndSetParent(ManifestEntry[] children, Mani
private ManifestEntry[] CopyChildren()
{
- var list = new List();
+ var list = new List(Children.Count);
for (int i = 0; i < Children.Count; i++)
{
var child = Children[i];
diff --git a/src/Http/Http/src/Features/RequestCookiesFeature.cs b/src/Http/Http/src/Features/RequestCookiesFeature.cs
index a89bb99f5df5..b0698ecdca52 100644
--- a/src/Http/Http/src/Features/RequestCookiesFeature.cs
+++ b/src/Http/Http/src/Features/RequestCookiesFeature.cs
@@ -80,7 +80,7 @@ public IRequestCookieCollection Cookies
}
else
{
- var headers = new List();
+ var headers = new List(_parsedValues.Count);
foreach (var pair in _parsedValues)
{
headers.Add(new CookieHeaderValue(pair.Key, pair.Value).ToString());
diff --git a/src/Http/Routing/src/Patterns/RoutePatternFactory.cs b/src/Http/Routing/src/Patterns/RoutePatternFactory.cs
index 8832e94e599d..9534ba6f6fb0 100644
--- a/src/Http/Routing/src/Patterns/RoutePatternFactory.cs
+++ b/src/Http/Routing/src/Patterns/RoutePatternFactory.cs
@@ -497,7 +497,7 @@ RoutePatternPart VisitPart(RoutePatternPart part)
updatedParameterPolicies = new Dictionary>(StringComparer.OrdinalIgnoreCase);
}
- parameterConstraints = new List();
+ parameterConstraints = new List(parameter.ParameterPolicies.Count);
updatedParameterPolicies.Add(parameter.Name, parameterConstraints);
}
diff --git a/src/Identity/Core/src/SignInManager.cs b/src/Identity/Core/src/SignInManager.cs
index f523b3319b5e..32ad02a16dfd 100644
--- a/src/Identity/Core/src/SignInManager.cs
+++ b/src/Identity/Core/src/SignInManager.cs
@@ -169,16 +169,22 @@ public virtual async Task CanSignInAsync(TUser user)
public virtual async Task RefreshSignInAsync(TUser user)
{
var auth = await Context.AuthenticateAsync(IdentityConstants.ApplicationScheme);
- var claims = new List();
+ IList claims = Array.Empty();
+
var authenticationMethod = auth?.Principal?.FindFirst(ClaimTypes.AuthenticationMethod);
- if (authenticationMethod != null)
- {
- claims.Add(authenticationMethod);
- }
var amr = auth?.Principal?.FindFirst("amr");
- if (amr != null)
+
+ if (authenticationMethod != null || amr != null)
{
- claims.Add(amr);
+ claims = new List();
+ if (authenticationMethod != null)
+ {
+ claims.Add(authenticationMethod);
+ }
+ if (amr != null)
+ {
+ claims.Add(amr);
+ }
}
await SignInWithClaimsAsync(user, auth?.Properties, claims);
@@ -203,9 +209,10 @@ public virtual Task SignInAsync(TUser user, bool isPersistent, string authentica
/// The task object representing the asynchronous operation.
public virtual Task SignInAsync(TUser user, AuthenticationProperties authenticationProperties, string authenticationMethod = null)
{
- var additionalClaims = new List();
+ IList additionalClaims = Array.Empty();
if (authenticationMethod != null)
{
+ additionalClaims = new List();
additionalClaims.Add(new Claim(ClaimTypes.AuthenticationMethod, authenticationMethod));
}
return SignInWithClaimsAsync(user, authenticationProperties, additionalClaims);
diff --git a/src/Middleware/Localization/src/RequestLocalizationOptions.cs b/src/Middleware/Localization/src/RequestLocalizationOptions.cs
index 95ca74fe32b5..c77c10dfe523 100644
--- a/src/Middleware/Localization/src/RequestLocalizationOptions.cs
+++ b/src/Middleware/Localization/src/RequestLocalizationOptions.cs
@@ -122,7 +122,7 @@ public RequestCulture DefaultRequestCulture
/// The .
public RequestLocalizationOptions AddSupportedCultures(params string[] cultures)
{
- var supportedCultures = new List();
+ var supportedCultures = new List(cultures.Length);
foreach (var culture in cultures)
{
@@ -140,7 +140,7 @@ public RequestLocalizationOptions AddSupportedCultures(params string[] cultures)
/// The .
public RequestLocalizationOptions AddSupportedUICultures(params string[] uiCultures)
{
- var supportedUICultures = new List();
+ var supportedUICultures = new List(uiCultures.Length);
foreach (var culture in uiCultures)
{
supportedUICultures.Add(new CultureInfo(culture));
diff --git a/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs b/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs
index 88f8ce93f4f4..842292f476c9 100644
--- a/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs
+++ b/src/Mvc/Mvc.Core/src/ApplicationModels/ApplicationModelFactory.cs
@@ -309,7 +309,7 @@ private static string CreateMixedRoutedActionDescriptorsErrorMessage(
// Text to show as the attribute route template for conventionally routed actions.
var nullTemplate = Resources.AttributeRoute_NullTemplateRepresentation;
- var actionDescriptions = new List();
+ var actionDescriptions = new List(actions.Count);
for (var i = 0; i < actions.Count; i++)
{
var (action, selector) = actions[i];
diff --git a/src/Mvc/Mvc.Core/src/ApplicationModels/ControllerActionDescriptorBuilder.cs b/src/Mvc/Mvc.Core/src/ApplicationModels/ControllerActionDescriptorBuilder.cs
index c53234af3e0e..9b2e8a951af1 100644
--- a/src/Mvc/Mvc.Core/src/ApplicationModels/ControllerActionDescriptorBuilder.cs
+++ b/src/Mvc/Mvc.Core/src/ApplicationModels/ControllerActionDescriptorBuilder.cs
@@ -63,7 +63,7 @@ private static void AddControllerPropertyDescriptors(ActionDescriptor actionDesc
private static void AddParameterDescriptors(ActionDescriptor actionDescriptor, ActionModel action)
{
- var parameterDescriptors = new List();
+ var parameterDescriptors = new List(action.Parameters.Count);
foreach (var parameter in action.Parameters)
{
var parameterDescriptor = CreateParameterDescriptor(parameter);
diff --git a/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs b/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs
index 3171c8f1aba8..f309c37ccc59 100644
--- a/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs
+++ b/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs
@@ -352,7 +352,7 @@ internal ActionModel CreateActionModel(
// This is fairly complicated so that we maintain referential equality between items in
// ActionModel.Attributes and ActionModel.Attributes[*].Attribute.
- var applicableAttributes = new List