Open
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
RegistryXmlRepository
takes a RegistryKey
as a parameter in its constructor (code ref), but that key is never disposed. Furthermore, if you construct this class inside a using block (see example), the class could attempt to access a closed registry key.
Expected Behavior
- Class should be disposable and dispose/close the key correctly.
- Possibly the class should reopen the key? Not sure.
Steps To Reproduce
- Setup a standard ASP.NET core web app
- Enable data protection for the app, persisting the data to the registry
- Ensure that the registry key is disposed in the setup method
- Notice that, when the protection information is accessed, the code will fail with an exception
using var registryKey = RegistryKey
.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
.OpenSubKey(some_registry_path, true);
dataProtectionBuilder.ProtectKeysWithDpapi(true).PersistKeysToRegistry(registryKey);
Exceptions (if any)
"Type":"System.ObjectDisposedException",
"Message":"Cannot access a closed registry key."
"Object name: 'key path set in code'."
.NET Version
8.0.400
Anything else?
- Is the key even supposed to be closed/disposed?
- If not, maybe the documentation for these extension methods/classes just needs updating