LightInject icon indicating copy to clipboard operation
LightInject copied to clipboard

.Net Core - Interception fails with Annotations turned on

Open scovel opened this issue 6 years ago • 2 comments

With the Annotation feature turned on, Interception fails. With it turned off Interception works, but I can't inject named instances using annotations.

            container.EnableAnnotatedConstructorInjection();
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLDNEA6J4RNI", Request id "0HLDNEA6J4RNI:00000003": An unh
andled exception was thrown by the application.
System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean&
 found)
   at LightInject.Annotation.AnnotatedConstructorDependencySelector.Execute(Cons
tructorInfo constructor) in C:\projects\lightinject-annotation\build\tmp\netstan
dard13\Binary\LightInject.Annotation\LightInject.Annotation.cs:line 167
   at LightInject.TypeConstructionInfoBuilder.GetConstructorDependencies(Constru
ctorInfo constructorInfo)
   at LightInject.TypeConstructionInfoBuilder.Execute(Registration registration)

   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Fu
nc`2 valueFactory)
   at LightInject.ServiceContainer.EmitNewDecoratorInstance(DecoratorRegistratio
n decoratorRegistration, IEmitter emitter, Action`1 pushInstance)
   at LightInject.ServiceContainer.EmitNewInstanceWithDecorators(ServiceRegistra
tion serviceRegistration, IEmitter emitter)
   at LightInject.ServiceContainer.<>c__DisplayClass147_0.<CreateEmitMethodWrapp
er>b__0(IEmitter ms)
   at LightInject.ServiceContainer.CreateDynamicMethodDelegate(Action`1 serviceE
mitter)
   at LightInject.ServiceContainer.CreateDelegate(Type serviceType, String servi
ceName, Boolean throwError)
   at LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boole
an throwError)
   at LightInject.ServiceContainer.TryGetInstance(Type serviceType)
   at LightInject.Scope.WithThisScope[T](Func`1 function)
   at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvid
er sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
   at lambda_method(Closure , IServiceProvider , Object[] )
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__Disp
layClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__Displa
yClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext contr
ollerContext)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next
, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilt
erAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilte
r>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecuted
Context context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope&
 scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsy
nc>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveN
ext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.<Invoke>d__3.Mov
eNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<
Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessReq
uestsAsync>d__2.MoveNext()

scovel avatar May 11 '18 19:05 scovel

Could you provide a small repro of this?

seesharper avatar May 15 '18 14:05 seesharper

TestLightInject.zip

Example attached.

scovel avatar May 22 '18 13:05 scovel