0

I am trying to over hand a RegistryKey to a class in my dll. Reading the Key into an temporary Key works(checked in debugger), but a NullReferenceException gets thrown when i try to assign it to the target RegistryKey-variable in that static class.

The following code is executed in the Constructor of the MainWindow (WPF-application)

try {
    RegistryKey tK;
    tK = Registry.ClassesRoot.OpenSubKey("Software").OpenSubKey("Software Untergrund");
    Options.SU = tK; //<= NullRefenceException gets thrown here
} catch (NullReferenceException e) {
    Console.WriteLine(e.StackTrace);
    throw;
}

Thanks for help in advance.

  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – gunr2171 Sep 18 '14 at 16:23
  • 1
    So is `Options` null? Is there special code attached to `SU` if it's a property? – gunr2171 Sep 18 '14 at 16:25
  • `RegistryKey tk = Registry.ClassesRoot;` try adding this inplace of `RegistryKey = tk` then possibly doing something like this `RegistryKey subKey = key.OpenSubKey("Software").OpenSubKey("Software Untergrund");` – MethodMan Sep 18 '14 at 16:40
  • @gunr2171: Options is a class that contains different properties like paths to specific folders etc. SU is a RegistryKey with the getter-method: RegistryKey SU {get; set;} – Trainfan884 Sep 18 '14 at 17:01
  • @DJKRAZE: the tK = ... line works, tK has content (subkeys etc.) when i try to assign it to Options.SU – Trainfan884 Sep 18 '14 at 17:02

0 Answers0