BackgroundDownloader.CreateDownload method not working in windows phone 8.1

368 Views Asked by At

I'm trying to download a file with this code:

private async void Button_Click(object sender, RoutedEventArgs e)
{
  try
  {
    Uri source;
    Uri.TryCreate(txbUri.Text.Trim(),UriKind.Absolute, out source);
    StorageFile destfile = await x.CreateFileAsync(Path.GetFileName(source.LocalPath), CreationCollisionOption.GenerateUniqueName);
    BackgroundDownloader downloader = new BackgroundDownloader();

    DownloadOperation download = await Task.Run(() => { return downloader.CreateDownload(source, destfile); });

    await HandleDownloadAsync(download, true);
  }
  catch(Exception ex)
  {
    MessageBox.Show(ex.ToString());  
  }
}

but there is a exception on the line:

downloader.CreateDownload(source, destfile);

the exception is:

class not registered

I Compiled Microsoft sample with the exact codes and it worked fine. But I don't know why my App Doesn't.

Just in case "x" is a StorageFolder object that picked by user.

0

There are 0 best solutions below