Created based on #93438
Repro
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddKeyedTransient<Service>(KeyedService.AnyKey);
// This line throws
// System.InvalidOperationException: 'The type of the key used for lookup doesn't match the type in the constructor parameter with the ServiceKey attribute.'
using var provider = services.BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true });
public class Service
{
public Service([ServiceKey] Service serviceKey)
{ }
}