I have a WebClient instance that receives data from a remote website. I referenced a DownloadProgressChanged event handler and I am trying to access InnerBuffer, which is an internal field in the DownloadBitsState nested class (set as private) in WebClient.
I am using the following code right in the DownloadProgressChanged event handler:
WebClient c = (WebClient)sender;
Type t = typeof(WebClient).GetNestedType("DownloadBitsState", BindingFlags.NonPublic);
FieldInfo m = t.GetField("InnerBuffer",BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
Debug.WriteLine(m.GetValue(c).ToString());
I get a runtime error: FieldAccessException (System.Net.WebClient+DownloadBitsState.InnerBuffer
)
Is there any way I can read this field or I simply cannot read the contents of internal fields?