title: Exception "The URI prefix is not recognized" from WebClient.DownloadDataAsync
body: <p>I was trying to save an image from an URL and I have an inner exception inside an inner exception tellin the URi prefix is not recognized.</p>
  <p>Full exception:</p>
  <pre><code>[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: 
  An exception occurred during the operation, making the result invalid. 
  Check InnerException for exception details. ---&gt; 
      System.Net.WebException: An exception occurred during a WebClient request. ---&gt;
           System.NotSupportedException: The URI prefix is not recognized.
  </code></pre>
  <p>Some code:</p>
  <pre><code>imagen_tap.Tapped += async (s, e) =&gt;
  {
     Console.WriteLine(&quot;URL IMAGE BRO::::::::: &quot; + imagen.Source.ToString());
     await api.DownloadImage(new Uri(imagen.Source.ToString()));
     string path = Preferences.Get(&quot;filePath&quot;, &quot;&quot;);
     await Launcher.OpenAsync(new OpenFileRequest { File = new ReadOnlyFile(path) });
  };
  
  
  public async Task DownloadImage(Uri URL)
          {
              WebClient webClient = new WebClient();
  
              string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), &quot;Images&quot;, &quot;temp&quot;);
              string fileName = URL.ToString().Split('/').Last();
              string filePath = Path.Combine(folderPath, fileName);
  
              webClient.DownloadDataCompleted += (s, e) =&gt;
              {
                  Directory.CreateDirectory(folderPath);
  
                  File.WriteAllBytes(filePath, e.Result); //Broken?
              };
  
              webClient.DownloadDataAsync(URL);
  
              Preferences.Set(&quot;filePath&quot;, filePath);
          }
  </code></pre>
  <p>EDIT: (forgot to add this)
  (NOT REAL URL)
  The URL is <a href="https://api.com/imagenes/partes/18005/2021062311191329243400.jpg" rel="nofollow noreferrer">https://api.com/imagenes/partes/18005/2021062311191329243400.jpg</a></p>
  <p>EDIT: (answering Jason, making sure if URL is correct on webClient)</p>
  <p><a href="https://i.stack.imgur.com/oXhTP.png" rel="nofollow noreferrer">Screenshot URI on webClient</a></p>
  <p><a href="https://i.stack.imgur.com/e88Oo.png" rel="nofollow noreferrer">Screenshot Opening localstorage</a></p>
  <p><a href="https://i.stack.imgur.com/BXLqA.png" rel="nofollow noreferrer">Screenshot Broken Line</a></p>
  <p><a href="https://i.stack.imgur.com/ZCDHD.png" rel="nofollow noreferrer">Screenshot e in debug</a></p>
  <p>EDIT:</p>
  <p>Well... I fixed the Uri prefix...</p>
  <p>I changed 2 things:
  In the Download Image I changed it from Task to string and returning a string.
  Code:</p>
  <pre><code>public string DownloadImageString(string URL)
          {
              WebClient webClient = new WebClient();
  
              string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), &quot;Images&quot;, &quot;temp&quot;);
              string fileName = URL.ToString().Split('/').Last();
              string filePath = Path.Combine(folderPath, fileName);
  
              webClient.DownloadDataCompleted += (s, e) =&gt;
              {
                  Directory.CreateDirectory(folderPath);
  
                  File.WriteAllBytes(filePath, e.Result);
              };
  
              webClient.DownloadDataAsync(new Uri(URL));
  
              return filePath;
          }
  </code></pre>
  <p>And then I changed the way I was sending the URL.</p>
  <p>Instead of sending a new Uri(url)
  I'm sending a string.
  That string is mounted manually again, not by taking imagen.Source (this was the real fix)
  Code:</p>
  <pre><code>Image imagen = new Image
                  {
                      Source = url + Foto.ID_Parte + &quot;/&quot; + Foto.Archivo
                  };
                  var imagen_tap = new TapGestureRecognizer();
                  imagen_tap.Tapped += async (s, e) =&gt;
                  {
                      string path = api.DownloadImageString(url + Foto.ID_Parte + &quot;/&quot; + Foto.Archivo);
                      await Launcher.OpenAsync(new OpenFileRequest { File = new ReadOnlyFile(path) });
                  };
                  
                  imagen.GestureRecognizers.Add(imagen_tap);
  </code></pre>