Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExplainCommand+Settings ctor fails ServiceProvider.ValidateService #1532

Closed
gitfool opened this issue Apr 26, 2024 · 2 comments · Fixed by #1534
Closed

ExplainCommand+Settings ctor fails ServiceProvider.ValidateService #1532

gitfool opened this issue Apr 26, 2024 · 2 comments · Fixed by #1534
Labels
bug Something isn't working needs triage

Comments

@gitfool
Copy link
Contributor

gitfool commented Apr 26, 2024

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/BoardGameGeek.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.

@gitfool gitfool added bug Something isn't working needs triage labels Apr 26, 2024
@github-project-automation github-project-automation bot moved this to Todo 🕑 in Spectre Console Apr 26, 2024
@gitfool
Copy link
Contributor Author

gitfool commented Apr 26, 2024

After poking around I think the obvious and simple fix is to remove the ctor and add property setters.

@maxarendsen
Copy link

I had the same problem. Using version 0.49.2-preview.0.16 solved this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
Status: Done 🚀
Development

Successfully merging a pull request may close this issue.

2 participants