-
Notifications
You must be signed in to change notification settings - Fork 5k
HttpClient exceptions are always culture specific #80424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsDescriptionI'm trying to get the exceptions messages of HttpClient in English but they are always in the current culture of Windows. Reproduction Stepsusing System.Globalization;
internal class Program
{
private static void Main(string[] args)
{
Go();
Console.ReadKey();
}
async static void Go()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
try
{
HttpResponseMessage webresponse = await new HttpClient().GetAsync("https://www.123blablablub.com");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
} Expected behavior
Actual behaviorDepending on the language of Windows, for example Spanish it would be: Regression?No response Known WorkaroundsNo response Configuration.NET 6, Windows 11, 64bit, Console / Winforms or WPF project Other informationNo response
|
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionI'm trying to get the exceptions messages of HttpClient in English but they are always in the current culture of Windows. Reproduction Stepsusing System.Globalization;
internal class Program
{
private static void Main(string[] args)
{
Go();
Console.ReadKey();
}
async static void Go()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
try
{
HttpResponseMessage webresponse = await new HttpClient().GetAsync("https://www.123blablablub.com");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
} Expected behavior
Actual behaviorDepending on the language of Windows, for example Spanish it would be: Regression?No response Known WorkaroundsNo response Configuration.NET 6, Windows 11, 64bit, Console / Winforms or WPF project Other informationNo response
|
Tagging subscribers to this area: @dotnet/area-system-resources Issue DetailsDescriptionI'm trying to get the exceptions messages of HttpClient in English but they are always in the current culture of Windows. Reproduction Stepsusing System.Globalization;
internal class Program
{
private static void Main(string[] args)
{
Go();
Console.ReadKey();
}
async static void Go()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
try
{
HttpResponseMessage webresponse = await new HttpClient().GetAsync("https://www.123blablablub.com");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
} Expected behavior
Actual behaviorDepending on the language of Windows, for example Spanish it would be: Regression?No response Known WorkaroundsNo response Configuration.NET 6, Windows 11, 64bit, Console / Winforms or WPF project Other informationNo response
|
This is not a globalization issue. This needs to be decided and handled on the level of the exception throwing and resource handling. Currently this is not supported except setting the current UI culture to English. |
This is a duplicate of #40427 |
@Symbai what exception you are getting in the case you mentioned? Is it Win32Exception? If so, then it is same as #40427. Just start read it from the comment #40427 (comment) |
Its HttpClient, so its System.Net.Http.HttpRequestException, not a Win32Exception. I cannot even cast it to a Win32Exception so I cannot use FormatMessageW. I still don't think its a duplicate. |
Your code throws the following:
So, it throws System.Net.Sockets.SocketException which is extending Win32Exception. It is same thing discussed in #40427 (comment). Basically, the message is coming from Windows OS and not from .NET. Windows cannot guarantee to carry English resources in all situations. There is some manual workaround here https://gist.github.com/ericstj/c72b90b0c12f86b7918850ee276fac3b which can help get the English message (if Windows has English resources). You can just pick SocketException.NativeErrorCode and call the extension method |
|
The workaround expected a Win32Exception as parameter so I tried casting it which obviously didn't worked. Didn't know about SocketException and native code field. I had to modify the workaround, now it works. Closing as duplicate. |
Description
I'm trying to get the exceptions messages of HttpClient in English but they are always in the current culture of Windows.
Reproduction Steps
Expected behavior
The specified host is unknown. (www.123blablablub.com:443)
Actual behavior
Depending on the language of Windows, for example Spanish it would be:
El host especificado es desconocido. (www.123blablablub.com:443)
Regression?
No response
Known Workarounds
No response
Configuration
.NET 6, Windows 11, 64bit, Console / Winforms or WPF project
Other information
No response
The text was updated successfully, but these errors were encountered: