-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should RegistryXmlRepository close the regkey between reads? #58224
Comments
I think the usual pattern is that the creator of the object disposes of it - normally, it's not a class or method that accepts it as an argument. I'm certainly open to examples or guidance showing evidence of a different approach. In the meantime, it seems like we mostly want to update the doc comment on I could also imagine having the registry close and re-open the regkey on demand, but I haven't thought through all the consequences of that. |
@amcasey Agree that normally the creator would dispose of the object. In this case it becomes a bit annoying for the consumer since they'd have to maintain a reference to the (opened) registry key for (potentially) the whole life of the application. |
@debracey Can you elaborate? At that point, wouldn't you just declare it without a |
Here's where DataProtection creates its own instance (as a fallback). It looks like it just doesn't use a |
@amcasey Yeah - what I meant to say was that, if you want to manually close/dispose the key, you'd have to maintain a reference to that key for the whole life of the application. Since the finalizer will take care of it, there's no practical reason to do this. Yes - the workaround I plan to use is to just remove the I am not aware of any problem with leaving the key open. We only found this issue after we were testing some stylecop/sonarqube suggestions and found that the suggestion(s) failed our pipelines with the exception mentioned above. |
Is there an existing issue for this?
Describe the bug
RegistryXmlRepository
takes aRegistryKey
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
Steps To Reproduce
Exceptions (if any)
.NET Version
8.0.400
Anything else?
The text was updated successfully, but these errors were encountered: