0
votes

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)

1
What is Logger?mjwills
@mjwills it is my logging method. log4net package is used for loggingIjas
@mjwills no i have tried stackoverflow.com/a/209259/34092 this but its not working.Ijas
I think the message is set when the exception is created. Changing the culture at a later time would not translate the message.JonasH

1 Answers

1
votes

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.