C# GetValue(..)返回null

C# GetValue(..)返回null,c#,registry,C#,Registry,我试图检索(REG_SZ)注册表项的值并将其写入字符串。但是,这段代码似乎认为密钥为null或不存在,并且不允许我GetValue()it。下面是我用来检索值的代码 string s64BasePath = "SOFTWARE\\Wow6432Node\\Xactware\\"; private void versionSelectorBox_SelectedIndexChanged(object sender, EventArgs e) { showForms(); sVers

我试图检索(REG_SZ)注册表项的值并将其写入字符串。但是,这段代码似乎认为密钥为null或不存在,并且不允许我
GetValue()
it。下面是我用来检索值的代码

string s64BasePath = "SOFTWARE\\Wow6432Node\\Xactware\\";
private void versionSelectorBox_SelectedIndexChanged(object sender, EventArgs e)
{
    showForms();
    sVersionSelected = versionServerBox.Text;
    if (b64Bit == true)
    {
        string sRKey = s64BasePath + sVersionSelected + "\\"; //Reads as SOFTWARE\\Wow6432Node\\Xactware\\Xactimate28\\
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(sRKey))
        {
            if (key != null)
            {
                //label1.Text = "Test."; //Reaches this point just fine
                Object o = key.GetValue("Location");
                if (o != null)
                {
                    //label1.Text = "Test."; //Does not reach this point, o = null?
                    sLocationKey = Convert.ToString(o);
                }
            }
        }
        //label1.Text = sLocationKey;
}
下面是注册表的外观。正如您所看到的,位置键存在于提供的路径中。然而,代码并没有落入最内部的if语句中,就像
o
对象为null一样


提前感谢。

老实说,没有安装Xactimate,我没有与您相同的注册表项,因此我使用Skype作为我的密钥

我改变了一件事,从\改为使用文字字符串标志。 仅供参考,我在LINQPad中运行了此命令,因此忽略“dump”命令

var test = @"SOFTWARE\Wow6432Node\Skype\Phone";
var reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(test);
reg.Dump("OpenSubKey: ");
var result = reg.GetValue("SkypeFolder");
result.Dump("GetValue: ");
下面是两次转储的结果

“//读作SOFTWARE\\Wow6432Node\\Xactware\\Xactimate28\\”是不正确的注释。那不是正在打开的钥匙。这是一个输入错误还是一个不同的键被访问?另外,不要为OpenSubKey提供尾随“\\”。如果附加调试器,则可以直接检查
对象-使用“监视”或“立即求值”窗口。我发现了问题所在,
sVersionSelected=versionServerBox.Text从错误的文本框中提取,我没有意识到。它的本意是从
versionSelectorBox
中获取,但多亏您给了我一些代码来解决我的问题,我才得以工作。谢谢