RestSharp: '' is not a supported encoding name

Steps to Reproduce the Problem

  1. var r = client.Execute(request);
  2. System.ArgumentException: ‘’’ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. Parameter name: name’
var client = new RestClient("https://api.trello.com");
var request = new RestRequest("/1/actions/592f11060f95a3d3d46a987a");
var content = client.Execute(request);

image

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 26 (7 by maintainers)

Most upvoted comments

@dfbarrios-adl just upgrade to the latest version. Already fixed in https://github.com/restsharp/RestSharp/pull/1341

My attempt to avoid the exception MiscExtensions.cs:

public static string AsString(this byte[] buffer, string encoding)
{
    Encoding enc;
    if (String.IsNullOrEmpty(encoding))
        enc = Encoding.UTF8;
    else
        try
        {
            enc = Encoding.GetEncoding(encoding);
        }
        catch (Exception)
        {
            enc = Encoding.UTF8;
        }

    return AsString(buffer, enc);
}

Paste the stacktrace and the code. One line is not enough.