You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Formerly, when a middleware type with multiple satisfiable constructors was instantiated from the dependency injection container, the one with the most parameters would be used. Now that only happens if the dependency injection container implements IServiceProviderIsService.
Version
.NET 9 RC 1
Previous behavior
Formerly, the first constructor was preferred (when both were satisfied) because it has more parameters.
publicclassCookiePolicyMiddleware{publicCookiePolicyMiddleware(RequestDelegatenext,IOptions<CookiePolicyOptions>options,ILoggerFactoryfactory){// Omitted for brevity}publicCookiePolicyMiddleware(RequestDelegatenext,IOptions<CookiePolicyOptions>options){// Omitted for brevity}}
New behavior
Now, neither constructor is preferred and construction fails with an error like
System.InvalidOperationException: 'Multiple constructors accepting all given argument types have been found in type 'Microsoft.AspNetCore.CookiePolicy.CookiePolicyMiddleware'. There should only be one applicable constructor.'
Type of breaking change
Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
Behavioral change: Existing binaries may behave differently at run time.
Reason for change
The activation mechanism was changed to help support keyed dependency injection.
Recommended action
If this happens and you can't upgrade to a dependency injection container that implements IServiceProviderIsService, you can add ActivatorUtilitiesConstructorAttribute to the preferred constructor of the affected middleware type.
Description
Formerly, when a middleware type with multiple satisfiable constructors was instantiated from the dependency injection container, the one with the most parameters would be used. Now that only happens if the dependency injection container implements
IServiceProviderIsService
.Version
.NET 9 RC 1
Previous behavior
Formerly, the first constructor was preferred (when both were satisfied) because it has more parameters.
New behavior
Now, neither constructor is preferred and construction fails with an error like
Type of breaking change
Reason for change
The activation mechanism was changed to help support keyed dependency injection.
Recommended action
If this happens and you can't upgrade to a dependency injection container that implements
IServiceProviderIsService
, you can addActivatorUtilitiesConstructorAttribute
to the preferred constructor of the affected middleware type.Affected APIs
This is known to cause errors when instantiating
Microsoft.AspNetCore.CookiePolicy.CookiePolicyMiddleware
with Autofac.Extensions.DependencyInjection 7.x.The text was updated successfully, but these errors were encountered: