How do I call JSON RPC API using C#? How do I access the JSON RPC API in C# in such a way that I can also read the errors that the interface provides?
I use the Newtonsoft.Json.Linq library as shown below to get the data.  Soon, I'll be posting Strongly typed C# client libraries at http://www.coinapi.net 

The main trick to getting the JSON error code is to call GetWebResponse() again in the catch method.  Then return and parse the data.  I've debated about including the WebException itself in the return code, but that may require too many changes. If anyone has ideas I'll be glad to take them.

        var ret = InvokeMethod("getblockhash", index);


Here is the definition of InvokeMethod

    public JObject InvokeMethod(string a_sMethod, params object[] a_params)
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url);
        webRequest.Credentials = Credentials;

        webRequest.ContentType = "application/json-rpc";
        webRequest.Method = "POST";

        JObject joe = new JObject();
        joe["jsonrpc"] = "1.0";
        joe["id"] = "1";
        joe["method"] = a_sMethod;

        if (a_params != null)
        {
            if (a_params.Length &gt; 0)
            {
                JArray props = new JArray();
                foreach (var p in a_params)
                {
                    props.Add(p);
                }
                joe.Add(new JProperty("params", props));
            }
        }

        string s = JsonConvert.SerializeObject(joe);
        // serialize json for the request
        byte[] byteArray = Encoding.UTF8.GetBytes(s);
        webRequest.ContentLength = byteArray.Length;

        try
        {
            using (Stream dataStream = webRequest.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }
        }
        catch (WebException we)
        {
            //inner exception is socket
            //{"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 23.23.246.5:8332"}
            throw;
        }
        WebResponse webResponse = null;
        try
        {
            using (webResponse = webRequest.GetResponse())
            {
                using (Stream str = webResponse.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(str))
                    {
                        return JsonConvert.DeserializeObject&lt;JObject&gt;(sr.ReadToEnd());
                    }
                }
            }
        }
        catch (WebException webex)
        {

            using (Stream str = webex.Response.GetResponseStream())
            {
                using (StreamReader sr = new StreamReader(str))
                {
                    var tempRet =  JsonConvert.DeserializeObject&lt;JObject&gt;(sr.ReadToEnd());
                    return tempRet;
                }
            }

        } 
        catch (Exception)
        {

            throw;
        }
    }