JasperFx / oakton

Parsing and Utilities for Command Line Tools in .Net
http://jasperfx.github.io/oakton
Apache License 2.0
308 stars 40 forks source link

Support Keyed services #86

Open ElanHasson opened 7 months ago

ElanHasson commented 7 months ago

Using .NET 8 and registered keyed services. Also using Lamar, Wolverine, Marten.

System.InvalidOperationException
  HResult=0x80131509
  Message=This service descriptor is keyed. Your service provider may not support keyed services.
  Source=Microsoft.Extensions.DependencyInjection.Abstractions
  StackTrace:
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ThrowKeyedDescriptor()
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.get_ImplementationType()
   at Oakton.Resources.ResourceHostExtensions.<>c.<AddResourceSetupOnStartup>b__0_0(ServiceDescriptor x)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Oakton.Resources.ResourceHostExtensions.AddResourceSetupOnStartup(IServiceCollection services, StartupAction action)
   at Program.<<Main>$>d__0.MoveNext() 
ElanHasson commented 4 months ago

I now know this was https://github.com/dotnet/runtime/issues/95789

https://github.com/JasperFx/oakton/blob/13b4228790e76b75cb468c5b3878565d267228c1/src/Oakton/Resources/ResourceHostExtensions.cs#L36

This is still an issue in Oakton. It's been fixed in Marten, and there is an open PR, https://github.com/JasperFx/lamar/pull/396 for Lamar in https://github.com/JasperFx/lamar/issues/395.

I'll setup a PR to fix this later today/tomorrow.