Thursday, September 22, 2011

Handling Silverlight exception 'System.UnauthorizedAccessException' in asynchronous http post problem


when you use asynchronous http post you should make sure that you use "Deployment.Current.Dispatcher.BeginInvoke" to a void "System.UnauthorizedAccessException" exception.

......


void DownloadNow()
{
      WebClient request = new WebClient();
      request.DownloadStringCompleted += new DownloadStringCompletedEventHandler(request_DownloadStringCompleted);
      request.DownloadStringAsync(serviceUri);
}


void request_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
      Deployment.Current.Dispatcher.BeginInvoke(() =>
              {
                 log.Text = e.Result;
              });
}

......

for more info please check this link http://forums.silverlight.net/t/66271.aspx/1?asynchronous+http+post+problem+System+UnauthorizedAccessException+Invalid+cross+thread+access+