Registry.LocalMachine returns null in RegistryPolicyResolver
Steve887 opened this issue · 2 comments
My application is using .net core Identity with Identity Server 4 to manage identity within my system.
I am trying to migrate up to .net core 2 and am running into a problem with the RegistryPolicyResolver.
My code sets up a WebHostBuilder using Kestrel and a Startup file to configure .net Identity and Identity Server:
var host = new WebHostBuilder().UseKestrel().UseUrls("localhost:44333")).UseStartup<IdentityStartup>();
host.Build().Start();
In IdentityStartup ConfigureServices
I am adding Data Protection like so:
services.AddDataProtection();
During start of the Web Host, I am getting a NullReferenceException in the constructor of RegistryPolicyResolver in the delegate of _getPolicyRegKey:
_getPolicyRegKey = () => Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DotNetPackages\Microsoft.AspNetCore.DataProtection");
The part that is null is Registry.LocalMachine
.
Is there anything else I need to configure to fix this error, or, preferably, is there any way to override or turn off using the Registry all together? I note that IRegistryPolicyResolver
is internal so I can just add my own version of it, and AddDataProtectionServices
in DataProtectionServiceCollectionExtensions
is private and always called so I can't override that.
You can override it with config - https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?tabs=aspnetcore2x
Did it actually crash, or did it log the exception and then tell you it was using ephemeral keys? If the latter, and you want to use the registry then you need to follow the configuration steps for IIS.
Closing due to no response.