why exception.message is not in english

0

I have a c# application

        try
        {
            using (var client = new WebClient())
            {
                client.DownloadFile(url, name);
                return true;
            }
        }
        catch (Exception e)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            Logger.Error("Error inside DownloadFile");
            Logger.Error(e.message);
            Logger.Error(e.InnerException);
        }

but i get error in non readable format

Error inside DownloadFile Œfi∑®¡¨Ω”µΩ‘∂≥Ã∑˛ŒÒ∆˜ System.Net.Sockets.SocketException (0x80004005): ”…”⁄ƒø±Íº∆À„ª˙ª˝º´æ‹æ¯£¨Œfi∑®¡¨Ω”°£ 108.160.165.189:443 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)

c#
exception
error-handling
asked on Stack Overflow Jan 19, 2021 by Ijas • edited Jan 19, 2021 by Ijas

1 Answer

1

The message in the exception is created when it's first thrown and that will be in whatever culture the code is compiled under. You cannot change this.

As this is WebClient the only solution is to make sure you have the English language version of .NET installed.

answered on Stack Overflow Jan 27, 2021 by ChrisF

User contributions licensed under CC BY-SA 3.0