我下面的代码失败,不管管理员与否:读取注册表值崩溃,如果我运行它
var suff = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\CCM\\LocationServices", true);
var value = suff.GetValue("DnsSuffix").ToString();
我得到我不能解码此错误消息:
An unhandled exception of type 'System.NullReferenceException' occurred in MyApp.exe Additional information: Object reference not set to an instance of an object.
我知道这个值存在,它也包含数据。
*编辑:就像我说的那样,它不应该为空,因为数据存在。如果它是空的,那么我将需要知道为什么它是空的。因此,关于什么是System.NullReferenceException
的问题完全不会帮助我。
的可能的复制[什么是一个NullReferenceException,如何解决呢?(http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i -fix-it) – Dmitry
@Dmitry就像我说过的,它不是null。或者如果是的话我不知道为什么。所以我相信这个问题是有效的。 – fishmong3r
*我知道这个值存在,它也包含数据。*您如何知道这一点?你认为它可能是一个x86键,而你的.NET应用程序在x64 CLR上运行(或相反)? –