`ExplainCommand+Settings` ctor fails `ServiceProvider.ValidateService`
gitfool opened this issue · comments
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?
Please upvote 👍 this issue if you are interested in it.
After poking around I think the obvious and simple fix is to remove the ctor and add property setters.