1

First I should clarify that my Proxy is set. The address and any necessary credentials are already successfully used in a login process to a web service. When downloading over a proxy, it is occasionally successful (~25% of the time), but most of the time it only partially downloads and "completes" with e.Error set (see below).

public static void DownloadMyFile(string file)
{
    Url = "https://myWebService.com/file.ext";

    using (var client = new WebClient())
    {
        client.Proxy = proxy; //proxy is set and used elsewhere prior to logging in

        //I use this event to manipulate my file when finished
        client.DownloadFileCompleted += client_DownloadCompleted;
        client.DownloadFileAsync(new Uri(Url), file);
    }
}

The event that I use later on:

public static void client_DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
     //e has an error here, no point in doing anything useful with the file

     //Do other "stuff"
}  

The inner exception text/stack trace is:

The decryption operation failed, see inner exception.

at System.Net.ConnectStream.EndRead(IAsyncResult asyncResult)
at System.Net.WebClient.DownloadBitsReadCallbackState(DownloadBitsState state, IAsyncResult result).

Again, to clarify: this works perfectly fine 100% of the time when not using a proxy.

Edit: The 2nd level inner exception message is The specified data could not be decrypted. There is no stack trace associated with it

Broots Waymb
  • 4,713
  • 3
  • 28
  • 51
  • What is the 2nd level inner exception? That should tell you what's failing... – Reed Copsey Aug 25 '15 at 21:39
  • @ReedCopsey, no luck: `The specified data could not be decrypted` is the 2nd level message. And there is no stack trace associated with it. – Broots Waymb Aug 25 '15 at 21:56
  • Is this busy waiting your real production code? Post the full exception ToString. Don't leave error details out. This is not a puzzle site. – usr Aug 25 '15 at 22:03
  • @usr, busy waiting was part of an attempted fix I found somewhere (not working, clearly). I just never removed it. And the ToString doesn't say anything different from that is posted... No details are left out, this is literally all I am given. – Broots Waymb Aug 26 '15 at 14:50
  • Why are you downloading asynchronously and then waiting? Just use `DownloadFile`. change the code to do that and then post the full exception ToString. – usr Aug 26 '15 at 15:03
  • @usr, I removed the waiting part since it was apparently creating some confusion and wasn't a cause (like I mentioned before, this is no longer in my code, same behavior). As for `DownloadFile`, I don't want to block anything in case the file is large enough to make an impact on this current thread (which it can, and did previously). I suppose I could try creating a thread from "scratch" and run `DownloadFile` from that separate thread? – Broots Waymb Aug 26 '15 at 15:14
  • Are you downloading from an https URL ? – HaukurHaf Aug 26 '15 at 15:15
  • @HaukurHaf, yes I am. It works perfectly fine with no proxy, and about 25% of the time with one. – Broots Waymb Aug 26 '15 at 15:19
  • Well, if you want to use async IO you should use await and possible use HttpClient although that is not required. Anyway, I don't understand why you don't want to provide the exception. We have no information to diagnose the issue with right now. I'll disengage from this question now and leave the guessing to others. – usr Aug 26 '15 at 15:19
  • The issue seems to be related to the use of a proxy and https communication, not wether the call is async or not. – HaukurHaf Aug 26 '15 at 15:22
  • @HaukurHaf, that's what I was thinking earlier (not sure why usr was getting attitude about it although I said I tried it "his way" earlier). I wish the exception was more clear than `The specified data could not be decrypted`... Time to do research I suppose. Still confusing why it still works some of the time. – Broots Waymb Aug 26 '15 at 15:25
  • 1
    Yes, this seems to be one of those hard to solve issues. Google-ing gives nothing helpful either. Perhaps you'll just have to do this another way ... skip the proxy or try downloading via a non-secure channel (if that's an option). You could also try using the new HttpClient class (.net 4.5) instead of the old WebClient. Or even go back to basics and use the more low level WebRequest class. – HaukurHaf Aug 26 '15 at 15:32
  • Why aren't you using the event `DownloadFileCompleted` instead? – Aron Aug 26 '15 at 15:36
  • @Aron, Sorry, typo. Will fix. – Broots Waymb Aug 26 '15 at 15:37
  • Can you try making a Minimal Complete example? – Aron Aug 26 '15 at 15:40
  • What else would you like me to include @Aron? There is quite a lot of code involved in this... Far too much for one question. – Broots Waymb Aug 26 '15 at 16:30
  • Less is more. Write the least amount of code required to get your problem. – Aron Aug 26 '15 at 17:06

0 Answers0