Reputation: 5729
I would like to read value in the registry using C#, if the values are not in the registry I create it. I have a reading problem:
RegistryKey regKey1 = Registry.CurrentUser;
regKey1 = regKey1.CreateSubKey(@"SOFTWARE\PNMDISPATCHER");
if (regKey1 != null)
{
textBoxTaux1.Text = regKey1.GetValue("Taux1").ToString();
}
I have the NullReferenceException
when execute the GetValue
function.
My values are in the registry, so why i get this error?
Upvotes: 0
Views: 3124
Reputation: 9639
Perhaps the NullReferenceException is for textBoxTaux1? Please post the call stack for the exception which should make this clear. You can use Exception.ToString() to get this.
Upvotes: 0
Reputation: 11201
Looks like the RegistryKey.GetValue is returning null and cannot do .ToString()
Taken from MSDN for RegistryKey.GetValue:
Retrieves the value associated with the specified name. Returns null if the name/value pair does not exist in the registry.
Upvotes: 1
Reputation: 34013
Well, apparently you didn't get the path right..
GetValue
returns a Null
when the key isn't found. Also check http://msdn.microsoft.com/en-us/library/fdf576x1
Can you debug through it and double check that the path you want to see, is indeed in the regKey1 variable at the textbox line?
Upvotes: 1