z4kn4fein / stashbox

A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
https://z4kn4fein.github.io/stashbox
MIT License
141 stars 10 forks source link

ApplicationInsights not compatible #78

Closed reservoir-dogs closed 4 years ago

reservoir-dogs commented 4 years ago

I can't use both : Microsoft.ApplicationInsights.AspNetCore 2.13.1 Stashbox.Extensions.Hosting 2.8.6

Can I help me ?

My Startup :

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddApplicationInsightsTelemetry();
        }

If i comment one or another, it works.

To reproduce use my repo : https://github.com/reservoir-dogs/WebApplicationWithStashBoxAndAppInsights

Exception is :

ArgumentNullException: Value cannot be null. (Parameter 'initializers[0]')
System.Dynamic.Utils.ContractUtils.RequiresNotNull(object value, string paramName, int index)

ArgumentNullException: Value cannot be null. (Parameter 'initializers[0]')
System.Dynamic.Utils.ContractUtils.RequiresNotNull(object value, string paramName, int index)
System.Dynamic.Utils.ExpressionUtils.RequiresCanRead(Expression expression, string paramName, int idx)
System.Linq.Expressions.Expression.NewArrayInit(Type type, IEnumerable<Expression> initializers)
System.Linq.Expressions.Expression.NewArrayInit(Type type, Expression[] initializers)
System.Linq.Expressions.ExpressionExtensions.InitNewArray(Type type, Expression[] initializers)
Stashbox.Resolution.Resolvers.EnumerableResolver.GetExpression(IContainerContext containerContext, IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Resolution.ResolutionStrategy.BuildAllResolutionExpressions(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation)
Stashbox.Resolution.Resolvers.EnumerableResolver.GetExpression(IContainerContext containerContext, IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Resolution.ResolutionStrategy.BuildAllResolutionExpressions(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation)
Stashbox.Resolution.Resolvers.EnumerableResolver.GetExpression(IContainerContext containerContext, IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilders.GenericTypeObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Resolution.ResolutionStrategy.BuildResolutionExpression(IContainerContext containerContext, ResolutionContext resolutionContext, TypeInformation typeInformation, IEnumerable<InjectionParameter> injectionParameters, bool forceSkipUnknownTypeCheck)
Stashbox.BuildUp.Expressions.ConstructorSelector.TryBuildResolutionConstructor(ConstructorInformation constructor, ResolutionContext resolutionContext, IContainerContext containerContext, IEnumerable<InjectionParameter> injectionParameters, out TypeInformation failedParameter, out Expression[] parameterExpressions, bool skipUknownResolution)
Stashbox.BuildUp.Expressions.ConstructorSelector.SelectConstructor(Type implementationType, IContainerContext containerContext, ResolutionContext resolutionContext, ConstructorInformation[] constructors, IEnumerable<InjectionParameter> injectionParameters)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateInitExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
Stashbox.BuildUp.Expressions.ExpressionBuilder.CreateExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
Stashbox.BuildUp.ObjectBuilders.DefaultObjectBuilder.GetExpressionInternal(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.BuildDisposalTrackingAndFinalizerExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.BuildUp.ObjectBuilderBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.LifetimeBase.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Lifetime.SingletonLifetime.GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.ConstructExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.Registration.ServiceRegistration.GetExpression(IContainerContext containerContext, ResolutionContext resolutionContext, Type resolveType)
Stashbox.ResolutionScope.Activate(ResolutionContext resolutionContext, Type type, object name)
Stashbox.ResolutionScope.Resolve(Type typeFrom, bool nullResultAllowed, object[] dependencyOverrides)
Stashbox.ResolutionScope.GetService(Type serviceType)
Stashbox.StashboxContainer.GetService(Type serviceType)
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService<T>(IServiceProvider provider)
Microsoft.Extensions.Hosting.HostBuilder.Build()
WebApplicationStashBoxAppInsights.Program.Main(string[] args) in Program.cs

Show raw exception details .NET Core 3.1.3 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 3.1.3

z4kn4fein commented 4 years ago

Thanks for reporting this issue, I'll look into it soon!

z4kn4fein commented 4 years ago

Hey, I found the issue, the fix will be in the next version, until that you can get rid of the error by configuring Stashbox like this:

Host.CreateDefaultBuilder(args)
    .UseStashbox(container => container.Configure(config => config.WithOptionalAndDefaultValueInjection()))
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
    });
reservoir-dogs commented 4 years ago

I tested it and it works! Thanks for your reactivity, that's key of success. When will you release the next version ?

z4kn4fein commented 4 years ago

Not sure yet, i have to cover some other issues first, I'll notify you when it's out. Then you can remove that config, it'll be part of the default functionality.