rmmarsh
asked on
Invalid cast while trying to read registry entry
I have the following code that is giving me the above error. Any idea why? how do I fix it? ( I have verified the value is "True")
RegistryKey networkStore = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Prager\\networkStore");
bool regKey = networkStore == null? false : (bool)networkStore.GetValue("networked");
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because the value is stored as "True", it has to be converted to boolean.
bool regKey = networkStore == null? false : Convert.ToBoolean(networkS tore.GetVa lue("netwo rked"));
This works like a champ. Thanks for your help anyway...
bool regKey = networkStore == null? false : Convert.ToBoolean(networkS
This works like a champ. Thanks for your help anyway...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the apology.
ASKER
Open in new window