Could not read key from registry (Exception from HRESULT: 0x80040150 (REGDB_E_READREGDB))

2

For a project at work we use Castle Windsor as our inversion of control container. In my team's project we depend on another team's WCF web services. The config for consuming these web services are set up in such a way that we will simply constructor inject the necessary interfaces from their library and then Castle Windsor creates and manages the WCF service instance.

This works fine for everyone in my team, except me. It used to work fine for me as well, but a couple of days ago I started getting the below stack trace whenever I hit code that require Castle Windsor to instantiate a WCF service:

Could not read key from registry (Exception from HRESULT: 0x80040150 (REGDB_E_READREGDB)) System.Runtime.InteropServices.COMException (0x80040150): Could not read key from registry (Exception from HRESULT: 0x80040150 (REGDB_E_READREGDB)) at System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(IntPtr pUnk) at System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) at Microsoft.Runtime.Hosting.StrongNameHelpers.get_StrongName() at Microsoft.Runtime.Hosting.StrongNameHelpers.StrongNameGetPublicKey(String pwzKeyContainer, Byte[] bKeyBlob, Int32 cbKeyBlob, IntPtr& ppbPublicKeyBlob, Int32& pcbPublicKeyBlob) at System.Reflection.StrongNameKeyPair.ComputePublicKey() at System.Reflection.StrongNameKeyPair.get_PublicKey() at System.Reflection.Emit.AssemblyBuilder..ctor(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource) at System.Reflection.Emit.AssemblyBuilder.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource) at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 assemblyAttributes, SecurityContextSource securityContextSource) at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) at Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName) at Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName() at Castle.DynamicProxy.ModuleScope.DefineType(Boolean inSignedModulePreferably, String name, TypeAttributes flags) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, IEnumerable`1 interfaces, TypeAttributes flags, Boolean forceUnsigned) at Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, Type parentType, IEnumerable`1 interfaces) at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope) at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory) at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) at Castle.Facilities.WcfIntegration.Async.AsynChannelFactoryBuilder`1.CreateChannelFactory(Type channelFactoryType, M clientModel, Object[] constructorArgs) at Castle.Facilities.WcfIntegration.AbstractChannelBuilder`1.CreateChannelCreator(Type contract, M clientModel, IChannelBuilderScope scope, Object[] channelFactoryArgs) at Castle.Facilities.WcfIntegration.AbstractChannelBuilder`1.Scope.Castle.Facilities.WcfIntegration.IWcfEndpointVisitor.VisitBindingAddressEndpoint(BindingAddressEndpointModel model) at Castle.Facilities.WcfIntegration.AbstractChannelBuilder`1.Scope.BuildChannelCreator() at Castle.Facilities.WcfIntegration.WcfClientActivator.CreateChannelCreator(IKernel kernel, ComponentModel model, IWcfClientModel clientModel, IWcfBurden& burden) at Castle.Facilities.WcfIntegration.WcfClientActivator.GetChannelCreator(CreationContext context, IWcfBurden& burden) at Castle.Facilities.WcfIntegration.WcfClientActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>c__DisplayClass1.<Resolve>b__0(Action`1 afterCreated) at Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>c__DisplayClass1.<Resolve>b__0(Action`1 afterCreated) at Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) at Betaling.Api.Ioc.WindsorWebApiIHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) in <PROJECT PATH REMOVED FOR COPYPASTE>\Ioc\WindsorWebApiIHttpControllerActivator.cs:line 21 at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

I'm not sure why a call to my machine's registry is necessary, but apparantly there is something extracted from there in order to generate either a public key or get the name of a key. As mentioned, this is only an issue on my computer. The same code (same commits) runs just fine for everyone else on my team and in our dev environments.

Any ideas or tips are welcome at this stage.

asp.net
windows
registry
castle-windsor
asked on Stack Overflow Sep 19, 2016 by ardal

2 Answers

1

In our case the issue was caused by the IIS app pool setting Load User Profile set to false. This allows Windows to unload registry files and causes REGDB_E_READREGDB error when accessing registry.

Load User Profile is populated as false by default by Microsoft Web Administration module used by DSC and needs to be explictly set to true

The similar problem with unloading registry files is described in this article

answered on Stack Overflow Sep 3, 2019 by Smok3r • edited Sep 3, 2019 by JavaTechnical
0

The strong name reading and writing functions of the .NET Framework are implemented in native code either in mscoree or maybe somewhere else now, and accessed via COM (therefore reading class names from the registry). You can see this in the reference source. It would seem that the .NET Framework has become corrupted on your machine.

I'd try the Microsoft .NET Framework Repair Tool, and then consider other options next if that doesn't work.

answered on Stack Overflow Sep 19, 2016 by Jonathon Rossi

User contributions licensed under CC BY-SA 3.0