Skip to content

ServiceKeyAttribute throws InvalidOperationException with ValidateOnBuild=true #114780

@steveharter

Description

@steveharter

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)
    { }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions