JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
571 stars 119 forks source link

WhatDoIHave() throws IndexOutOfRangeException in v6.0.0 #294

Closed hellfirehd closed 2 years ago

hellfirehd commented 3 years ago

In dev I always log WhatDidIScan() and WhatDoIHave() on startup. After upgrading to v6.0.0 it started throwing the following:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at LamarCodeGeneration.ReflectionExtensions.ShortNameInCode(Type type)
   at Lamar.IoC.Diagnostics.WhatDoIHaveWriter.writeServiceType(IServiceFamilyConfiguration serviceType, TextReportWriter reportWriter)
   at Lamar.IoC.Diagnostics.WhatDoIHaveWriter.<>c__DisplayClass5_0.<writeSummary>b__2(IServiceFamilyConfiguration svc)
   at LamarCodeGeneration.Util.EnumerableExtensions.Each[T](IEnumerable`1 values, Action`1 eachAction)
   at Lamar.IoC.Diagnostics.WhatDoIHaveWriter.writeSummary(IEnumerable`1 serviceTypes, StringWriter writer)
   at Lamar.IoC.Diagnostics.WhatDoIHaveWriter.writeContentsOfServiceTypes(IEnumerable`1 serviceTypes, StringWriter writer, WhatDoIHaveDisplay display)
   at Lamar.IoC.Diagnostics.WhatDoIHaveWriter.GetText(ModelQuery query, String title, WhatDoIHaveDisplay display)
   at Lamar.IoC.Scope.WhatDoIHave(Type serviceType, Assembly assembly, String namespace, String typeName)
   at CPCA.Logging.LoggingExtensions.WhatDoIHave(IHost host) in D:\Source\CPCAv4\source\CPCA.Infrastructure\Logging\LoggingExtensions.cs:line 37
   at CPCA.WebUI.Server.Program.Main(String[] args) in D:\Source\CPCAv4\source\CPCA.WebUI.Server\Program.cs:line 38

I can do a Live Share session if it would help.

jdub4237 commented 3 years ago

I had this exact same issue in a previous version after adding

services.AddHttpClient();

to my Startup.cs config, but in version 6 I now get this instead:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

   at Lamar.IoC.Instances.CtorArg..ctor(ParameterInfo parameter, Instance instance)
   at Lamar.IoC.Instances.ConstructorInstance.determineArgument(ServiceGraph services, ParameterInfo parameter)
   at Lamar.IoC.Instances.ConstructorInstance.<>c__DisplayClass29_0.<buildOutConstructorArguments>b__0(ParameterInfo x)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable``1 source)
   at Lamar.IoC.Instances.ConstructorInstance.buildOutConstructorArguments(ServiceGraph services)
   at Lamar.IoC.Instances.ConstructorInstance.createPlan(ServiceGraph services)
   at Lamar.IoC.Instances.Instance.CreatePlan(ServiceGraph services)
   at Lamar.IoC.Instances.ConstructorInstance.buildOutConstructorArguments(ServiceGraph services)
   at Lamar.IoC.Instances.ConstructorInstance.createPlan(ServiceGraph services)
   at Lamar.IoC.Instances.Instance.CreatePlan(ServiceGraph services)
   at Lamar.ServiceGraph.planResolutionStrategies()
   at Lamar.ServiceGraph.buildOutMissingResolvers()
   at LamarCodeGeneration.Util.PerfTimer.Record(String text, Action action)
   at Lamar.ServiceGraph.Initialize(PerfTimer timer)
   at Lamar.IoC.Scope..ctor(IServiceCollection services, PerfTimer timer)
   at Lamar.Container..ctor(IServiceCollection services)
   at Lamar.Microsoft.DependencyInjection.LamarServiceProviderFactory.CreateServiceProvider(ServiceRegistry containerBuilder)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateServiceProvider(Object containerBuilder)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Program.Main(String[] args)
jeremydmiller commented 2 years ago

Good times. I'm on it.

jeremydmiller commented 2 years ago

I'm hardening the code to trap exceptions and just use Type.Name if it can't figure it out, but I can't reproduce this locally guy. @jdub4237's problem is unrelated.

jeremydmiller commented 2 years ago

for @jdub4237 I added better exceptions, but I have no idea what that's from, and again, I'm not able to reproduce the issue locally.