Q
I am trying to use reflection to access the private property of
OpenFileDialog fileNames property. I have the following code :
filedlg.InitialDirectory = directory.Text;
filedlg.Filter = "xml files (*.xml)|*.xml" ;
filedlg.FileName = "*.xml";
filedlg.ValidateNames = false;
if (filedlg.ShowDialog() == DialogResult.Cancel)
return;
Type t = filedlg.GetType();
PropertyInfo rowsPropertyInfo = t.GetProperty("fileNames",
BindingFlags.Instance |
BindingFlags.Static |
BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.NonPublic|
BindingFlags.SuppressChangeType);
object[] o = (object[])rowsPropertyInfo.GetValue(filedlg,
BindingFlags.Instance |
BindingFlags.Static |
BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.NonPublic|
BindingFlags.SuppressChangeType,
null, null, null);
I got an error :
An unhandled exception of type 'System.NullReferenceException' occurred in
BGReport.exe
Additional information: Object reference not set to an instance of an
object.
Any idea ? Thanks.
OpenFileDialog fileNames property. I have the following code :
filedlg.InitialDirectory = directory.Text;
filedlg.Filter = "xml files (*.xml)|*.xml" ;
filedlg.FileName = "*.xml";
filedlg.ValidateNames = false;
if (filedlg.ShowDialog() == DialogResult.Cancel)
return;
Type t = filedlg.GetType();
PropertyInfo rowsPropertyInfo = t.GetProperty("fileNames",
BindingFlags.Instance |
BindingFlags.Static |
BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.NonPublic|
BindingFlags.SuppressChangeType);
object[] o = (object[])rowsPropertyInfo.GetValue(filedlg,
BindingFlags.Instance |
BindingFlags.Static |
BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.NonPublic|
BindingFlags.SuppressChangeType,
null, null, null);
I got an error :
An unhandled exception of type 'System.NullReferenceException' occurred in
BGReport.exe
Additional information: Object reference not set to an instance of an
object.
Any idea ? Thanks.