ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
337 stars 33 forks source link

Error inside Container #116

Closed tiagorosendo closed 7 years ago

tiagorosendo commented 7 years ago

When i try to run inside a container with aspnet:2.0 base image, i get this error:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Win32.Registry' threw an exception. ---> System.PlatformNotSupportedException: Registry is not supported on this platform. at Microsoft.Win32.RegistryKey.OpenBaseKeyCore(RegistryHive hKey, RegistryView view) at Microsoft.Win32.Registry..cctor() --- End of inner exception stack trace --- at Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.<>c.<.ctor>b2_0() at Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.ResolvePolicy() at Microsoft.AspNetCore.DataProtection.Internal.KeyManagementOptionsSetup.Configure(KeyManagementOptions options) at Microsoft.Extensions.Options.OptionsFactory1.Create(String name) at Microsoft.Extensions.Options.OptionsManager1.<>c__DisplayClass5_0.b0() at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue() at Microsoft.Extensions.Options.OptionsCache1.GetOrAdd(String name, Func1 createOptions) at Microsoft.Extensions.Options.OptionsManager1.Get(String name) at Microsoft.Extensions.Options.OptionsManager1.get_Value() at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager..ctor(IOptions1 keyManagementOptions, IActivator activator, ILoggerFactory loggerFactory) at lambda_method(Closure , IExportLocatorScope , IDisposalScope , IInjectionContext ) at Grace.DependencyInjection.Lifestyle.SingletonLifestyle.ProvideLifestyleExpression(IInjectionScope scope, IActivationExpressionRequest request, Func2 activationExpression) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetExpressionFromStrategyCollection(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpressionFromStrategies(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ConstructorExpressionCreator.GetParameterExpression(ParameterInfo parameter, ConstructorParameterInfo parameterInfo, IInjectionScope injectionScope, TypeActivationConfiguration configuration, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ConstructorExpressionCreator.GetParameterExpressionsForConstructor(IInjectionScope injectionScope, TypeActivationConfiguration configuration, IActivationExpressionRequest request, ConstructorInfo constructor) at Grace.DependencyInjection.Impl.Expressions.ConstructorExpressionCreator.CreateExpression(IInjectionScope scope, IActivationExpressionRequest request, TypeActivationConfiguration activationConfiguration) at Grace.DependencyInjection.Impl.Expressions.TypeExpressionBuilder.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request, TypeActivationConfiguration activationConfiguration) at Grace.DependencyInjection.Lifestyle.SingletonLifestyle.ProvideLifestyleExpression(IInjectionScope scope, IActivationExpressionRequest request, Func2 activationExpression) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetExpressionFromStrategyCollection(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpressionFromStrategies(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ConstructorExpressionCreator.GetParameterExpression(ParameterInfo parameter, ConstructorParameterInfo parameterInfo, IInjectionScope injectionScope, TypeActivationConfiguration configuration, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ConstructorExpressionCreator.GetParameterExpressionsForConstructor(IInjectionScope injectionScope, TypeActivationConfiguration configuration, IActivationExpressionRequest request, ConstructorInfo constructor) at Grace.DependencyInjection.Impl.Expressions.ConstructorExpressionCreator.CreateExpression(IInjectionScope scope, IActivationExpressionRequest request, TypeActivationConfiguration activationConfiguration) at Grace.DependencyInjection.Impl.Expressions.TypeExpressionBuilder.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request, TypeActivationConfiguration activationConfiguration) at Grace.DependencyInjection.Lifestyle.SingletonLifestyle.ProvideLifestyleExpression(IInjectionScope scope, IActivationExpressionRequest request, Func`2 activationExpression) at Grace.DependencyInjection.Impl.Expressions.ArrayExpressionCreator.GetActivationExpressionResultsFromStrategies(IInjectionScope scope, IActivationExpressionRequest request, Type arrayElementType) at Grace.DependencyInjection.Impl.Expressions.ArrayExpressionCreator.GetArrayExpressionList(IInjectionScope scope, IActivationExpressionRequest request, Type arrayElementType) at Grace.DependencyInjection.Impl.Expressions.ArrayExpressionCreator.GetArrayExpression(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request) at Grace.DependencyInjection.Impl.ActivationStrategyCompiler.LocateEnumerableStrategy(IInjectionScope scope, Type locateType, ActivationStrategyFilter consider, Object key) at Grace.DependencyInjection.Impl.ActivationStrategyCompiler.FindDelegate(IInjectionScope scope, Type locateType, ActivationStrategyFilter consider, Object key, IInjectionContext injectionContext, Boolean checkMissing) at Grace.DependencyInjection.Impl.InjectionScope.InternalLocate(IExportLocatorScope scope, IDisposalScope disposalScope, Type type, ActivationStrategyFilter consider, Object key, IInjectionContext injectionContext, Boolean allowNull, Boolean isDynamic) at Grace.DependencyInjection.Impl.InjectionScope.LocateOrDefault(Type type, Object defaultValue) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()

ipjohnson commented 7 years ago

Can you attach your Program.cs and Startup.cs? It looks like something going sideways in the DataProtection code but I'm not sure why.

ipjohnson commented 7 years ago

Also what platform are you on .net core 2.0, net 4.6.2? Windows, linux?

ipjohnson commented 7 years ago

Ok I was able to track the problem down to a change MS made to their own code and opened an issue. I'll look at adding some type of black listing feature for concrete types that works off names (the type is internal so it has to be name not typeof()).

Sorry you have to be the guinea pig, I didn't realize they were making so many DI refactoring changes that would ripple like this.

ipjohnson commented 7 years ago

This won't be addressed till MS releases asp.net core 2.1 so to bridge that gap I'll add a feature to Grace to allow you to black list types from being auto-registered (Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver specifically).

I'll see about doing a release in the next couple days to add this feature.

davidfowl commented 7 years ago

Sorry about this 😞

ipjohnson commented 7 years ago

@davidfowl these things happen especially when you have so many moving part that can be swapped in and out.

tiagorosendo commented 7 years ago

@ipjohnson thanks for the fast support, i will wait for the Grace release =D

ipjohnson commented 7 years ago

@tiagorosendo I've pushed a beta package if you could give it a whirl that would be great.

You'll need to add a call to ExcludeTypeFromAutoRegistration in your configuration code.

container.Configure(c =>
       c.ExcludeTypeFromAutoRegistration("Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver"));
ipjohnson commented 7 years ago

@tiagorosendo I'm going to close this out and push an official release tomorrow. Let me know if you run into any other asp.net 2.0 compatibility issues. Thanks.