Skip to content

[dotnet-sdk-10.0.100-preview.1.25103.13] OrchardCMS retarget failed with ambiguous call error between custom GetKeyedService() and Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetKeyedService() #60307

Open
@Junjun-zhao

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When retargeting OrchardCMS app to .NET 10, it is built failed with CS0212 error

The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetKeyedService(System.IServiceProvider, System.Type, object?)' and 'OrchardCore.Environment.Shell.Builders.ServiceProviderExtensions.GetKeyedService(System.IServiceProvider, System.Type, object?)'

Application Name: OrchardCMS
OS: Windows 10 22H2
CPU: X64
.NET Build Number: dotnet-sdk-10.0.100-preview.1.25103.13
App Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2380573

Github Link:
https://github.com/OrchardCMS/OrchardCore

Verify Scenarios:
1). Windows10 21h2 x64 + dotnet-sdk-8.0.405 + default target 8.0: Pass
2). Windows10 21h2 x64 + dotnet-sdk-9.0.102 + retarget 9.0: Pass
3). Windows10 21h2 x64 + dotnet-sdk-10.0.100-preview.1.25103.13 + default 8.0: Pass
4). Windows10 21h2 x64 + dotnet-sdk-10.0.100-preview.1.25103.13-win-x64 + retarget10.0: Fail

Expected Behavior

Build successful.

Steps To Reproduce

Minimal Repro Steps:(Attached demo:)
Make sure the machine has dotnet-sdk-dotnet-sdk-10.0.100-preview.1.25103.13 installed.

  1. Create a .NET 9 Asp.NET Core Web project.
  2. Create a Shell folder and add a ShellClass.cs file with below code:
using Microsoft.Extensions.DependencyInjection;

namespace WebApplication1.Shell
{
    public static class ServiceProviderExtensions
    {
        public static object? GetKeyedService(this IServiceProvider provider, Type serviceType, object? serviceKey)
        {
            ArgumentNullException.ThrowIfNull(provider);
            if (provider is IKeyedServiceProvider keyedServiceProvider)
            {
                return keyedServiceProvider.GetKeyedService(serviceType, serviceKey);
            }

            throw new InvalidOperationException("This service provider doesn't support keyed services.");
        }
    }
}
  1. Add a TestClass.cs class file under project root with below code:
 using WebApplication1.Shell;

namespace WebApplication1
{
    public class TestClass(IServiceProvider services)
    {
        public object GetKeyedService(Type serviceType, object serviceKey)
        => services.GetKeyedService(serviceType, serviceKey);
    }
}
  1. Retarget the project to .NET 10:
<PropertyGroup>
  <TargetFramework>net10.0</TargetFramework>
  <Nullable>enable</Nullable>
  <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
  1. Build the project.

Exceptions (if any)

Build Failed with below error:

The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetKeyedService(System.IServiceProvider, System.Type, object?)' and 'WebApplication1.Shell.ServiceProviderExtensions.GetKeyedService(System.IServiceProvider, System.Type, object?)'

.NET Version

10.0.100-preview.1.25103.13

Anything else?

DotNet Info:

.NET SDK:
 Version:           10.0.100-preview.1.25103.13
 Commit:            9035d02b05
 Workload version:  10.0.100-manifests.bf5105ba
 MSBuild version:   17.14.0-preview-25073-02+291a81087

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-preview.1.25103.13\

Host:
  Version:      10.0.0-preview.1.25080.5
  Architecture: x64
  Commit:       b98cabca12

.NET SDKs installed:
  10.0.100-preview.1.25103.13 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.0-preview.1.25103.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.0-preview.1.25080.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 10.0.0-preview.1.25080.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions