[Mono-dev] RegistryKey.OpenSubKey behavior

Juan Cristóbal Olivares cristobal at cxsoftware.com
Sat Jan 25 17:32:41 UTC 2014


Hi guys:

I was working with a third party library and got this exception:

Unhandled Exception:
System.Security.SecurityException: No access to the given key (see
stacktrace [1]).

This exception is thrown when calling

Microsoft.Win32.RegistryKey.OpenSubKey (string name, bool writable)

with the second parameter = true.

This is a minimum example (see full code [2]):

var localMachine = Registry.LocalMachine;
Console.WriteLine (localMachine);
var test = localMachine.OpenSubKey("ThisIsATest", true);
Console.WriteLine("Test key: {0}", test);
if (test != null)
        test.Close();
localMachine.Close();

According to the documentation [3], "If the requested key does not exist,
this method returns null instead of throwing an exception.".

I tested this on Windows (.Net Framework 4) and works as expected -returns
null instead of an exception-.

Let me know what do you think.

I could fix this if you want. I'm not sure how to proceed. I have not
contributed for a while :) Should I send a patch or a pull request? Please
let me know!

Regrads,
JCO

References:
[1] http://pastebin.com/P4uHntLK
[2] http://pastebin.com/vrRfpF4P
[3] http://msdn.microsoft.com/en-us/library/xthy8s8d%28v=vs.110%29.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140125/86dd2629/attachment.html>


More information about the Mono-devel-list mailing list