0

I have very simple code that download files from a web server and here is the code. As i said it is very basic

// use the web client to download
using (var client = new WebClient())
{
    // download locally
    client.DownloadFile(from, to);
}

But for some client the file does not download completely and does not throw exception. All these client come from different location and all have the same behavior that the WebClient download exactly 10 mb of ANY file above 10mb. A 8mb file is 8mb, a 20mb file is 10mb a 34 mb file is 10mb. The funny thing is we ask those user to stop using the software.

This issue is not related to the computer as we have alot of those user on laptop that the download works fine from home and it doesn't when they are at work and some it's totally reverse, the download doesn't work at work but it does at work. The behavior is also different for client within the same physical office.

We have tried to talk to their IT and they have no problem going on our http browsable directory and downloading many files over 10mb and it works perfectly and they state they never had such issue. The issue seems to spread more and more and since last windows 10 update much more client started to have this issue.

As a side note this download code has been unchanged and running for 5 years with nearly no issues.

Does anyone know why download would complete without any error (in try..catch) without having downloaded the whole file ? and Why would all these different client with the issue would be cut at EXACTLY 10,000 bytes.

Wanted to add that we tried to reinstall .NET Framework for these user in the past without any result thinking it must be an issue with that

I just edited to add this little extra details that the files they are trying to download are on an anonymous access folder so no login required and it is browsable. All user with the issue can use Chrome and Edge to navigate to the folder and right-click and download and the file is complete that way. Only .NET cannot download files above 10mb on their PC.

Franck
  • 4,438
  • 1
  • 28
  • 55
  • Does this help any? https://stackoverflow.com/questions/2269607/how-to-programmatically-download-a-large-file-in-c-sharp https://stackoverflow.com/questions/11881893/webclient-downloads-an-incomplete-file https://stackoverflow.com/questions/12976047/webclient-downloadstringuri-uri-has-10-mb-file-can-i-download-a-certain-size – DCCoder Nov 04 '20 at 16:25
  • Does it hanging up at this threshold of 10k bytes? Or it completes as if it would be succeed? – Alexander Burov Nov 04 '20 at 16:27
  • Does the site you're downloading the file from require a login? Instead of downloading the file, it might just be downloading some html code that basically says you need to log in. – Icemanind Nov 04 '20 at 16:29
  • There's a decent chance the site you're downloading from doesn't _want_ you downloading files in this way, and they've got a mechanism set up where if their server doesn't get an indication that you're using the right client every so often they cut off the download. (I'm envisioning a situation like YouTube videos) – StriplingWarrior Nov 04 '20 at 16:32
  • the website does not require login it's anonymous access. That download code run in a loop of hundreds of file and manage to do them all except the 10k byte+ one that never download completely. Also download location is from my different web servers – Franck Nov 04 '20 at 16:38
  • If servers are under your control - I'd check servers (logs) rather than client. – Evk Nov 04 '20 at 19:09
  • @Evk server log are perfectly fine. All 200 status code and for one in particular that i like to use as a test which is 35mb i have between 18 to 25 seconds time taken. I would have something else than status 200 if it didn't work. Unless IIS falsely report errors to log files which i wish they don't – Franck Nov 04 '20 at 19:27
  • Yes but I'd except status 200 because with error status client would also throw exception. Anyway, I'd try to enable network tracing on client to gather more details: https://learn.microsoft.com/en-us/dotnet/framework/network-programming/network-tracing – Evk Nov 04 '20 at 19:35
  • @Evk good tip i'll take a look. Might take a while as most user are on road salesman and because time zones but worth trying asap. – Franck Nov 04 '20 at 19:43
  • @Evk I enabled the network tracking and it works. All bytes are downloaded successfully. The file on disk does not match the downloaded content. so the problem is within .NET itself. there is a problem in the `DownloadFile()` method between all bytes received and the moment it write the file to disk which doesn't throw any exception. – Franck Nov 05 '20 at 14:21
  • Well, then the next thing I'd try is removing WebClient and try something else, like regular `HttpWebRequest`, it's not like `WebClient` does a lot anyway. Maybe your .NET framework version is old? Cannot imagine such bug could survive for that long, if that's a bug indeed. – Evk Nov 05 '20 at 14:27
  • @Evk, `HttpWbRequest` doesn't work either. already tried that. I am running .NET Framework 4.8 and as i mention is the post reinstalling it was one of the thing we tried out of despair. – Franck Nov 05 '20 at 14:48
  • @Evk after another hour of investigation it is indeed an issue within .NET. Following the packets individually it just suddenly stop to download and doesn't throw any exception. A fatal flaw in .Net framework that i just cannot deal with right now. Gotta use another language and refactor every single part of the software that does a download of any kind. – Franck Nov 05 '20 at 16:44

0 Answers0