aspnetcore: [9.0.100-rc.1.24406.1] EasyCMS app launch failed with 'Multiple constructors accepting all given argument types have been found in type 'Microsoft.AspNetCore.CookiePolicy.CookiePolicyMiddleware' exception

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When running the 3rd party application with the latest .NET 9.0 build (9.0.100-rc.1.24406.1), it failed launch with below exception message: 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.'

Findings: We found this issue is caused by Autofac.Extensions.DependencyInjection version 7.1.0 nuget package. If we upgrade the package to latest version 9.0.0, the issue will gone. But the Autofac.Extensions.DependencyInjection version 7.1.0 package works when running against with build dotnet-sdk-9.0.100-preview.7.24402.8, it starts failing on build dotnet-sdk-9.0.100-rc.1.24406.1.

Application Name: EasyCMS OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-rc.1.24406.1 App Source or App Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2198684 Github Link: https://github.com/yushuo1990/EasyCMS

Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.303: Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24402.8: Pass 3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.1.24406.1: Fail

Expected Behavior

App launch successfully.

Steps To Reproduce

App Repro steps on repro machine:(Please refer to the Repro Machine information from** Internal bug) 1.Open “C:\EasyCMS\App\EasyCMS\App\Atlass.Framework.Web.runtimeconfig.json” file . 2. Change the “Atlass.Framework.Web.runtimeconfig.json” file to let the app run against with dotnet-sdk-9.0.100-rc.1.24406.1

"framework": {
      "name": "Microsoft.AspNetCore.App",
      "version": "9.0.0-rc.1.24405.8"
    },
  1. Launch C:\EasyCMS\App\EasyCMS\App\Atlass.Framework.Web.exe.

Expected Result: Launch successfully.

Actual Result: Launch failed with below error in Command prompt window:

Unhandled exception. 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.
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.TryFindMatchingConstructor(Type instanceType, Type[] argumentTypes, ConstructorInfo& matchingConstructor, Nullable`1[]& parameterMap)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type instanceType, Type[] argumentTypes, ConstructorInfoEx[] constructors, ConstructorInfo& matchingConstructor, Nullable`1[]& matchingParameterMap)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.CreateMiddleware(RequestDelegate next)
   at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__14_1(IHostedService service, CancellationToken token)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at Atlass.Framework.Web.Program.Main(String[] args) in C:\Users\Appcompat\Desktop\EasyCms\Atlass.Framework.Web\Program.cs:line 31

Minimal Repro steps (attached WebApplication1.zip): The minimal repro project under C:\WebApplication1 on repro machine (Please refer to the Repro Machine information from Internal bug) 1.Create a .NET 5.0 ASP.NET Core MVC project. (We select .NET 5 because it has the same target framework and same project structure with testing app) 2. Install Autofac.Extensions.DependencyInjection version 7.1.0 nuget package. 3. Add following code in Program.cs file:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
    .UseServiceProviderFactory(new AutofacServiceProviderFactory())
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });
  1. Add following code in Startup.cs file:
app.UseCookiePolicy();
app.UseHttpsRedirection();
  1. Build the project.
  2. Update “bin\Debug\net5.0\WebApplication1.runtimeconfig.json” to run against with dotnet-sdk-9.0.100-rc.1.24406.1:
"framework": {
      "name": "Microsoft.AspNetCore.App",
      "version": "9.0.0-rc.1.24405.8"
    },
  1. Press F5 to start the app.

Exceptions (if any)

App launch failed with below exception:

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.'

Stack Trace:
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.TryFindMatchingConstructor(Type instanceType, Type[] argumentTypes, ConstructorInfo& matchingConstructor, Nullable`1[]& parameterMap)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type instanceType, Type[] argumentTypes, ConstructorInfoEx[] constructors, ConstructorInfo& matchingConstructor, Nullable`1[]& matchingParameterMap)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.CreateMiddleware(RequestDelegate next)
   at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__40.MoveNext()
   at Microsoft.Extensions.Hosting.Internal.Host.<<StartAsync>b__14_1>d.MoveNext()
   at Microsoft.Extensions.Hosting.Internal.Host.<ForeachService>d__17`1.MoveNext()
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__14.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at WebApplication1.Program.Main(String[] args) in E:\Demos\WebApplication1\WebApplication1\Program.cs:line 17

.NET Version

9.0.100-rc.1.24406.1

Anything else?

Dotnet Info:

.NET SDK:
 Version:           9.0.100-rc.1.24406.1
 Commit:            b149a156f2
 Workload version:  9.0.100-manifests.c127569d
 MSBuild version:   17.12.0-preview-24405-01+85d805a5a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-rc.1.24406.1\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      9.0.0-rc.1.24403.1
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  9.0.100-rc.1.24406.1 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-rc.1.24405.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-rc.1.24403.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.1.24404.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 22 (22 by maintainers)

Most upvoted comments

The “official” ActivatorUtilities does use match length as a tie-breaker if the container supports IServiceProviderIsService, which Autofac.Extensions.DependencyInjection does as of version 7.2.

That’s my understanding as well. Thanks for checking in, @tillig!

The internal ActivatorUtilities used match length as a tie-breaker, whereas the “official” one does not.