vendredi 26 août 2016

PropertyInfo.GetProperty returns null when it shouldn't

I'm trying to get the value of a private property of a WPF WebBrowser object. I can see in the debugger that it has a non-null value.

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...

My guess is I'm not using reflection in a proper way, but what is the proper way to do it in this case?





Aucun commentaire:

Enregistrer un commentaire