Skip to content

ExplainCommand+Settings ctor fails ServiceProvider.ValidateService #1532

@gitfool

Description

@gitfool

Information

  • OS: Windows
  • Version: 11 23H2
  • Terminal: Windows Terminal

Describe the bug
After upgrading Spectre.Console.Cli from 0.48.0 to 0.49.1 (gitfool/BoardGame.Dungeon#240) I see that dependency injection service provider validation now fails when running a debug build with the "development" environment:

System.InvalidOperationException
  HResult=0x80131509
  Message=Error while validating the service descriptor 'ServiceType: Spectre.Console.Cli.ExplainCommand+Settings Lifetime: Singleton ImplementationType: Spectre.Console.Cli.ExplainCommand+Settings': Unable to resolve service for type 'System.String[]' while attempting to activate 'Spectre.Console.Cli.ExplainCommand+Settings'.
  Source=Microsoft.Extensions.DependencyInjection
  StackTrace:
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(ServiceDescriptor descriptor) in Microsoft.Extensions.DependencyInjection\ServiceProvider.cs:line 198

  This exception was originally thrown at this call stack:
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceIdentifier, System.Type, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain, System.Reflection.ParameterInfo[], bool) in CallSiteFactory.cs
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceIdentifier, System.Type, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain) in CallSiteFactory.cs
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Microsoft.Extensions.DependencyInjection.ServiceDescriptor, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceIdentifier, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain, int) in CallSiteFactory.cs
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Microsoft.Extensions.DependencyInjection.ServiceDescriptor, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain) in CallSiteFactory.cs
    Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(Microsoft.Extensions.DependencyInjection.ServiceDescriptor) in ServiceProvider.cs

Inner Exception 1:
InvalidOperationException: Unable to resolve service for type 'System.String[]' while attempting to activate 'Spectre.Console.Cli.ExplainCommand+Settings'.

To Reproduce
Clone https://github.com/gitfool/BoardGameGeek.Dungeon then run a debug build with the "development" environment.

Expected behavior
This previously did not and now should not fail validation.

Additional context
It does not fail when running a debug build with the "production" environment since validation is then disabled.

This seems to be due to the ExplainCommand+Settings ctor; is there a reason for this ctor or can it be removed?

public Settings(string[]? commands, bool? detailed, bool includeHidden)
{
Commands = commands;
Detailed = detailed;
IncludeHidden = includeHidden;
}

Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageSomeone needs to take a look at this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions