Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1099793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:47:14+00:00 2026-05-17T00:47:14+00:00

I have a WebClient instance that receives data from a remote website. I referenced

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:47:14+00:00Added an answer on May 17, 2026 at 12:47 am

    It’s possible that the field you want is write only. Use reflector to look at the source to see what is going on. If it’s write only then you will need to access the private field.

    Also: He IS passing in the reference using m.GetValue(c) as c is the instance of sender cast as Webclient.

    BTW: Make sure WebClient is not null.

    –Edit: After posting my answer I realize that you’re trying to access a property of a type that isnt instantiated. Doh! Does Webclient have a property that has an instance of DownloadBitsState? Use that, THEN pull the property

    –Edit: Looking at the code, the only method in webclient that instantiates DownloadBitsState is private byte[] DownloadBits()

    private byte[] DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp)
    {
        WebResponse response = null;
        DownloadBitsState state = new DownloadBitsState(request, writeStream, completionDelegate, asyncOp, this.m_Progress, this);
        if (state.Async)
        {
            request.BeginGetResponse(new AsyncCallback(WebClient.DownloadBitsResponseCallback), state);
            return null;
        }
        response = this.m_WebResponse = this.GetWebResponse(request);
        int bytesRetrieved = state.SetResponse(response);
        while (!state.RetrieveBytes(ref bytesRetrieved))
        {
        }
        state.Close();
        return state.InnerBuffer;
    }
    

    So, you can’t really do what you want in the way you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Per a client's request I have written a communication class that inherits from webclient.
I have a WebClient and I'm subscribing to the OnDownloadStringCompleted event handler. When the
I have a download manager of sorts that uses WebClient.DownloadFileAsync. Webclient doesn't seem to
I have a class that implements the IDisposable interface. I am using a webclient
i have an application that loads the page content. I use the WebClient class.
I have a WebClient that is fired multiple times in the same class and
I'm trying to use WebClient to download a bunch of files asynchronously. From my
Edit: This is done in the Compact Framework, I don't have access to WebClient
I have written some data fetch service which fetches some entities from main web
I have a client program that is getting an httpresponsemessage from a WCF rest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.