skumar.snl 0 Newbie Poster

hi,

We are showing Video with slides(images) in silverlight .Our images come from amazon server now we want to cache these images before starting Video.

our code is given below:

private void LoadImage(string ImageURL)
    {

        WebClient downloader = new WebClient();
        downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
        string fileName = ImageURL;
        downloader.OpenReadAsync(new Uri(fileName, UriKind.Absolute));
    }


    void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {

       //  Create a new BitmapImage and load the stream

        BitmapImage loadedImage = new BitmapImage();
        loadedImage.SetSource(e.Result);


    }

But it gives following Error in e.Result:

System.Reflection.TargetInvocationException was unhandled by user code
  Message=An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.
  StackTrace:
       at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
       at System.Net.OpenReadCompletedEventArgs.get_Result()
       at Video_PowerPoint.Session.downloader_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
       at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
       at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
  InnerException: System.Security.SecurityException
       Message=""
       StackTrace:
            at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
            at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)
       InnerException: System.Security.SecurityException
            Message=Security error.
            StackTrace:
                 at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
                 at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
            InnerException:

Please Throw some light on this error . Is this the right way to cache image ?? Any other suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.