Note that there are some explanatory texts on larger screens.

plurals
  1. POMoonlight, WebClient and "Exception has been thrown by the target of an invocation"
    text
    copied!<p>I'm writing a little engine to download text from some .php files, I've done this engine in Visual c# and I haven't got problems.</p> <p>I'm doing this:</p> <pre><code> [ ... ] WebClient client = null; try { client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler( CompleteDownload ); client.AllowReadStreamBuffering = true; client.DownloadStringAsync( new Uri( "http://blabla/bla.php" ) ); } catch (Exception e) { lbl1.Text = e.Message; } [ ... ] </code></pre> <p>And this to "catch" the downloaded data:</p> <pre><code>public void CompleteDownloadPcops( object sender, DownloadStringCompletedEventArgs ea ) { if ( ea.Error == null ) { try{ lbl1.Text = ea.Result; } catch(Exception e) { lbl2.Text = e.Message; } } } </code></pre> <p>Executing this code I get, on <code>lbl1</code> the exception <code>Exception has been thrown by the target of an invocation</code>, result of <code>lbl1.Text = ea.Result;</code> in <code>CompleteDownload</code>. Why? And, after knowing the reason, how I can solve it?</p> <p>More info: I'm using moonlight in monodevelop 2.4 on Ubuntu 11.04 platform.</p> <p><strong>UPDATE</strong></p> <p>I've update my system to MonoDevelop 2.6 as you recomended me. Now, doing the same, I've get an error on <code>ea.Error</code>. The message is (in spanish):</p> <p><code>System.Security.SecurityException ---&gt; System.Security.SecurityException: Error de seguridad. en System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) en System.Net.Browser.BrowserHttpWebRequest.&lt;&gt;c__DisplayClass5.&lt;EndGetResponse&gt;b__4(Object sendState) en System.Net.Browser.AsyncHelper.&lt;&gt;c__DisplayClass4.&lt;BeginOnUI&gt;b__1(Object sendState) --- Fin del seguimiento de la pila de excepciones internas --- en System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) en System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) en System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) en System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)</code>.</p> <p>The full code I'm using now is:</p> <pre><code>public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void btn1_Click(object sender, RoutedEventArgs e) { WebClient client = null; try { client = new WebClient(); client.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(client_DownloadStringCompleted); client.AllowReadStreamBuffering = true; client.DownloadStringAsync(new Uri("http://carles.lambdafunction.com/a/try.php")); } catch (Exception ex) { lbl1.Text = ex.Message; btn1.Content = "A"; } } void client_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e) { if (e.Error == null) { try { lbl2.Text = e.Result; } catch (Exception ex) { lbl1.Text = ex.Message; lbl2.Text = ex.InnerException.ToString(); btn1.Content = "C"; } } else { lbl1.Text = e.Error.ToString(); btn1.Content = "B"; txt1.Text = e.Error.ToString(); } } } </code></pre> <p>You can see the output of the <em>web call</em> (to the dummy page /p/try.php), it's really simple. Really, now, I'm lost because I'm following this tutorial: <a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx</a> .</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload