2

I am sending a request to Facebook Graph API by using WebClient with the following code that is written in an ASP.net MVC Controller class:

 WebClient client2 = new WebClient();

        Stream data2 = client2.OpenRead("https://graph.facebook.com/me&" + s);
        StreamReader reader2 = new StreamReader(data); //Error


        string s2 = reader2.ReadToEnd();
        data2.Close();
        reader2.Close();

        s2=s2.Substring(s2.IndexOf('"', s2.IndexOf(':')), s2.Length - s2.IndexOf('"', s2.IndexOf(':')));

        s2= s2.Substring(1, s2.IndexOf('"', 1) - 1);

        return "AccessToken Stored in session, Current Signed in user is: "+s2;

I am getting this error: "System.ArgumentException: Stream was not readable." at the line commented as //Error. This request to https://graph.facebook.com returns data in JSON format. Is that causing this exception? Please help. How do I resolve this issue?

1 Answer 1

2

I might be pointing out the obvious, but you are passing the "data" variable into the StreamReader constructor right after creating the "data2" variable. I am guessing that you meant to pass in "data2" instead?

Sign up to request clarification or add additional context in comments.

2 Comments

Oh such a silly mistake by me. Thanks for pointing out. This was exactly the problem. :$
No worries. I have definitely made that same mistake as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.