Locked WebClient throws WebException.UnknownError

  • Thursday, April 05, 2012 4:49 PM
     
     

    I'm using WebClient to download files from my server. However, I've started seeing increasingly high numbers of users who fail to start the download and instead they get a System.Net.WebException.UnknownError back.

    That exception obviously doesn't provide much information as to what went wrong. Does anybody know what could be causing this or how I can figure out what's going on?

    • Moved by Leo Liu - MSFT Friday, April 06, 2012 4:42 AM Moved for better support. (From:Visual C# General)
    •  

All Replies

  • Thursday, April 05, 2012 7:01 PM
     
     

    Could you provide a code snippet? Did you try to perform a trace of the running program to determine the exact point where the exception is raised?

    Bye.


    Luigi Bruno - Microsoft Community Contributor 2011 Award

  • Thursday, April 05, 2012 7:05 PM
     
     

    Hi Luigi,

    What kind of code snippet are you looking for specifically?

    I haven't been able to perform a trace (e.g. via a debugger) since this happens on user computers and the only reason I know about this is due to telemetry data. If there's anything I can do code-wise to pull out more information, however, I'm all ears.

  • Thursday, April 05, 2012 7:21 PM
     
     

    It could be useful to know when the problem arises (for example, during a specific operation): if you can try executing the application from within the Visual Studio IDE to see when the execption is raised, it could be easy to uderstand what's going wrong.
    That exception is not very useful: you know that is a generic error message that does not provide further informations.

    Bye.


    Luigi Bruno - Microsoft Community Contributor 2011 Award

  • Thursday, April 05, 2012 7:28 PM
     
     

    That exception is not very useful: you know that is a generic error message that does not provide further informations.

    Haha, that's why I'm asking because there's no information whatsoever as to what's going wrong, and as I said above, this happens on a bunch of users' computers, not mine, so I don't have a debugger available.

    I'm simply calling DownloadFileAsync() to download the file, but the DownloadFileCompleted event is fired with WebException.UnknownError.

    Any thoughts or ideas on what could cause this to happen is much appreciated. There are error values for connection issues, TLS issues and timeouts, so it sounds like it's something else.

  • Thursday, April 05, 2012 8:53 PM
     
     

    I suggest writing a test program which uses WebRequest to see what's the source of the error. Because WebRequest gives you complete control over the request and receiving the response while WebClient abstracts away (hides) all the settings. By the way, you can yourself be one of those users and debug in Visual Studio as Luigi said, can't you? (Or you are sitting behind the server!)

  • Thursday, April 05, 2012 11:35 PM
     
     

    I suggest writing a test program which uses WebRequest to see what's the source of the error. Because WebRequest gives you complete control over the request and receiving the response while WebClient abstracts away (hides) all the settings. By the way, you can yourself be one of those users and debug in Visual Studio as Luigi said, can't you? (Or you are sitting behind the server!)

    Wouldn't using HttpWebRequest just return the same exception as WebClient does? As far as I know, the WebException is actually propagated from the underlying WebRequest that WebClient uses under the hood, but I might be wrong there.

    The problem here is that the issue is happening on users' computers. I haven't reproduced it on my end so far or else I would've debugged it long ago. As I said earlier, the only reason I know about this issue is due to telemetry data that our users' clients submit to us, but the exception coming out from WebClient tells me absolutely nothing about what's going wrong. I just know it's happening quite frequently.

    Is there's anything I can do to pull out more information about what went wrong *without* having a debugger attached?

  • Sunday, April 08, 2012 4:55 AM
     
     

    Even without a debugger you can get more information on this issue, because network packets can tell a lot of the underlying.

    You can utilize Microsoft Network Monitor,

    http://www.microsoft.com/download/en/details.aspx?id=4865

    Or System.NET tracing,

    http://support.microsoft.com/kb/947285

    Then you can analyze the network conversation captured when the exception occurs, and soon identify what happens on the wire.

    Regards,


    Lex Li (http://lextm.com)

  • Sunday, April 08, 2012 7:06 PM
     
     

    Not to sound ungrateful or anything, but as I've said multiple times above, I do not have access to the computers with these problems. The only reason I know about it is because I'm getting a disturbingly high number of telemetry reports with this very non-descriptive exception. These users are not getting in touch with me when the issue occurs, so I have no way of testing anything outside of the code.

    That's why I'm looking for one of two things:

     1. A way I can pull out more information about this error programmatically.

     2. Feedback from somebody at e.g. Microsoft who knows what could potentially throw this exception in large amounts when I'm attempting to start an asynchronous download of a file (I know that's a very broad question, but I'm keeping my fingers crossed for psychic debugging).

  • Sunday, April 08, 2012 9:25 PM
     
     
    You don't need to debug on the computer that is having the problem.  You could trace all internet traffic at a getway computer and then isolate the problem by comparing the time of the error with the captured trace.  You can use System.NET tracing at the gateway.

    jdweng

  • Sunday, April 08, 2012 9:30 PM
     
     
    You don't need to debug on the computer that is having the problem.  You could trace all internet traffic at a getway computer and then isolate the problem by comparing the time of the error with the captured trace.  You can use System.NET tracing at the gateway.

    jdweng

    You're asking me to capture all HTTP traffic on my (Linux-based) web server and hopefully correlate this with something on the user's end? Sounds infeasible.

    You're also assuming the user is even getting to the point of talking to my server. If that were the case, wouldn't I either be getting a response back or some other TCP-related exception, such as ConnectFailure, ReceiveFailure or SendFailure?

  • Sunday, April 08, 2012 9:34 PM
     
     
    Then use the error string as a trigger and only save the data just before and just after the error condition.  I've done this lots of times with hardware sniffers.

    jdweng

  • Sunday, April 08, 2012 9:37 PM
     
     
    Then use the error string as a trigger and only save the data just before and just after the error condition.  I've done this lots of times with hardware sniffers.

    jdweng

    I'm still not sure I follow. Who would save what data? Are you saying I enable network tracing for all my users just to catch issues that only apply to some potentially slowing everybody down while doing so?
  • Monday, April 09, 2012 3:47 AM
     
     

    From your last two postings I can tell you  have a lot of experience, and so do I.  I worked 5 years as a network engineering testing IP networks.  My company was developing IP software on an embedded processor and my job was to do beta testing on the software.

    You and I know there are two methods of solving problems like this.

    1) Getting lucky and finding somebody else who have seen this problems.  That is what you have already done.

    2) Rolling up your sleeves and doing the hard job of debugging the problem one step at a time which is what I'm proposing.  I don't think your are going to get lucky!  Don't blame me for being realistic.  I know nothing about the size of your network, how often the problem is occuring, or the amount of memory your gateway has to capture data.

    At my company we had limited amount of memory on our embedded processor and had to use external test equipment to capture data to find these type problems.  The external test equipement had triggers and filters so once we  knew about a problem we cold start isolating the problem by only capturing data going to certain IP addresses and/or message with specific data patterns.


    jdweng

  • Monday, April 09, 2012 4:37 AM
     
     

    I'm sorry if I came across as cocky. That wasn't my intention. I have no problem getting my hands dirty and getting to the bottom of this problem. That's why I asked here in case somebody had a good suggestion for where I could start.

    The problem is that I'm not clear exactly what you're asking me to do. "My network" is the Internet. Our web installer downloads the installation package from our web server and in some odd cases .NET throws back an UnknownError. That's a very different situation than the confined company network that you're describing.

    What I'm asking for is help on how to dig deeper into this exception.

    I do not believe it's feasible to enable network tracing for every single user just to catch these one-offs (since it has a negative effect on performance). I will definitely check our server logs to see whether we even hear anything from these users (IP-wise), but I also don't believe it's remotely feasible for our web server to log all requests and responses.

    With that said, I was hoping there was a way I could pull out more data about what went wrong when I *do* know something went wrong, i.e. the UnknownError exception was thrown.

    I, too, am trying to be realistic here and I'm not willing to sacrifice performance for the rest of our users while we're attempting to investigate this issue. Perhaps somebody has seen this exception crop up under certain conditions? That sort of thing.

  • Monday, April 09, 2012 5:59 AM
     
     

    Soren

    A suggestion came to my mind. See if it is usefull. Try writing a simple test program in an unmanaged language such as Delphi 7.0, VB 6.0, Visual C++ 6.0. You can also write a COM DLL and call its methods in your .NET app.

    This suggestion might seem ridiculious at first. But the point is getting to the source of the error. If the error is because of the server it doesn't differ what program or code (managed/unmanaged) has sent the request. So the error again will raise. Then in the unmanaged codoe there could be more information about the error.



  • Monday, April 09, 2012 9:17 AM
     
     
    First check you server event logs to see if there ae any error messages in the logs.  Also see if there is any patterns to the failures (time of day, destination IP, Protocol).  Since the requests are coming from your own server, I would defrag the server file system and amybe do a disk check. You could just be exceeding some time outs.  You also could be having some corrupted data on your ethernet.  Maybe a bad router.  Also do a code check of your .Net code to see if you have all the TRY and Catch statements.  the error may be caused in one section of the code, but being caught in another section.

    jdweng

  • Tuesday, April 10, 2012 6:24 AM
     
      Has Code

    If you're using Apache web server, I think you can use SetEnvIf configuration (section Conditional Logs) to log client activity from specific IP address to specifc log file.


    # Mark requests from the specific address
    SetEnvIf Remote_Addr "123\.123\.123\.123" clientdebug
    # Log what matches the address
    CustomLog logs/clientdebug_log common env=clientdebug

    With this, you can log a bunch of address that reported the same problem. Just remeber to comment the Customlog line out and perform graceful restart of HTTPD when done.

    • Edited by cheong00 Tuesday, April 10, 2012 6:25 AM
    • Edited by cheong00 Tuesday, April 10, 2012 6:26 AM
    • Edited by cheong00 Tuesday, April 10, 2012 6:31 AM
    •  
  • Wednesday, August 01, 2012 8:10 PM
     
     

    I hope I am not answering too late, but I found at least one condition under which this happens:

    If you are trying to Download a file to a destination folder which doesn't exist, then the WebClient just cancels the download with the "UnknownError" WebException, without giving any further details in the message of the WebException. However, the InnerException of the WebException in this case would be a DirectoryNotFoundException with the message "Could not find a part of the path [your_path]".

    Hope this helps!


    Avamboo UG (haftungsbeschränkt) | Hochfeldstr. 2 | 86159 Augsburg | Germany www.avamboo.de