我想获取WPF WebBrowser对象的私有属性值。在调试器中可以看到它具有非空值。
PropertyInfo activeXProp = Browser.GetType().GetProperty("ActiveXInstance", BindingFlags.Instance | BindingFlags.NonPublic);
object activeX = activeXProp.GetValue(Browser, null); // here I get null for the activeX value
activeX.GetType().GetProperty("Silent").SetValue(activeX, true); // and here it crashes for calling a method on a null reference...
我猜测我没有正确使用反射,但是在这种情况下应该如何正确地使用呢? 该项目是一个在.NET 4.6.1和Windows 10上运行的WPF项目。 我尝试以管理员权限运行它(添加到项目中的清单文件),但是没有任何改变。
activeX
是null
吗?它并没有返回 null。 - undefinedactiveX.GetType().GetProperty("Silent")
返回了null
。 - undefinedactiveX
确实为空,那就是在没有创建窗口并尝试访问它时为空。 - undefined