views:

200

answers:

1

I got a strange bug report the other day and was hoping someone might be able to help me figure out the culprit. I've got a plug-in that uses the Facebook API to make calls from a desktop client program. A user reports that when he turns on Vista's Parental Controls, he gets a run-time exception.

The detailed bug report is available here, and I've verified that Vista's Parental Controls is indeed the problem. Even if no sites are blocked, and even if http://api.facebook.com is specifically allowed, I still get the exception.

The offending method is below. Specifically, the line string result = reader.ReadToEnd(); is where the exception is thrown.

    private static XmlDocument ExecuteQuery(SortedDictionary<string, string> parameters,
        string secretKey)
    {
        string query = GetQueryFromParameters(parameters, secretKey);
        HttpWebResponse response = null;

        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FACEBOOK_REST_URL);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Write the POST parameters to Facebook.
            StreamWriter writer = new StreamWriter(request.GetRequestStream());
            writer.Write(query);
            writer.Close();

            // Get a response.
            response = request.GetResponse() as HttpWebResponse;
        }
        catch (WebException we)
        {
            // Getting the response must have thrown an HTTP error. We can still try to get the 
            // response from the caught exception though.
            response = we.Response as HttpWebResponse;
        }

        if (response != null)
        {
            // Read the response.
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string result = reader.ReadToEnd();
            reader.Close();
            response.Close();

            XmlDocument responseXml = new XmlDocument();
            responseXml.LoadXml(result);
            return responseXml;
        }
        else
        {
            throw new FacebookException(Resources.FacebookResponseError);
        }
    }

Obviously, I should be catching the IOException, rather than letting it become a run-time exception. But even so, the problem still stands. I've spent some time Googling the issue, but came up with nothing regarding Parental Controls.

Any suggestions? Thanks!

A: 

Well, I can't figure out why the exception is thrown, but at least if I just catch it and do nothing then the reader still reads to the end and all of the result is saved.