Cashif Ilyas February 2016

Simple WebClient not working: Customized cultures cannot be passed by LCID, only by name

I am trying to send a simple POST request to a URL using WebClient but I am getting

An exception occurred during a WebClient request.

And in InnerException

Customized cultures cannot be passed by LCID, only by name.

Apparently there is no discussion about this exception on the internet.

Here is my code:

public static void Send(string message)
{
    var url = "https://api.mailgun.net/v3/sandbox1ebb54bdb39044988d3c916d833769b7.mailgun.org/messages";
    using (var client = new WebClient())
    {
        client.Credentials = new NetworkCredential("api", "some_password");
        var values = new NameValueCollection();
        values["from"] = "Mailgun Sandbox <postmaster@sandbox1ebb54bdb39044988d3c916d833769b7.mailgun.org>";
        var response = client.UploadValues(url, values);
        var responseString = Encoding.Default.GetString(response);
        Reader.log(responseString);
    }
}

Exception is raised at client.UploadValues(url, values)

Answers


Cashif Ilyas February 2016

Apparently, it is a known issue with older versions of .NET (if your System Locale is not US) https://connect.microsoft.com/VisualStudio/feedback/details/1741767/compiler-error-customized-cultures-cannot-be-passed-by-lcid-only-by-name

Moving to the .NET 4.0 or higher solves the issue.

Post Status

Asked in February 2016
Viewed 1,033 times
Voted 6
Answered 1 times

Search




Leave an answer