2011-07-12 101 views
2

我目前正在Silverlight中開發一個小應用程序,最近嘗試使用它,我爲我的應用程序啓用了瀏覽器外部署。但是,現在,在禁用設置後,運行應用程序立即在加載完成後立即拋出異常。啓用Silverlight瀏覽器外瀏覽器突破瀏覽器內應用程序

未處理的異常('未處理的錯誤在Silverlight應用程序 代碼:4004 類別:ManagedRuntimeError 消息:System.Reflection.TargetInvocationException:在操作過程中出現的異常,使結果無效

但是,如果我只是在瀏覽器中打開TestPage.html應用仍然有效,因爲它沒有。

任何想法?謝謝

+0

很奇怪!你有沒有嘗試在你的Silverlight代碼開始時設置一箇中斷點,並且看看你是否可以得到一條失敗的線? – NickHeidke

+0

我做了,並且在構造函數後面的App.xaml.cs中出現錯誤。 我創建了一個新的silverlight項目並複製了所有的.xaml和.cs,並且它再次正常工作。仍然會有興趣找到問題。 – MarkNach

+0

發佈此異常的InnerException。這是真的出錯了。 –

回答

0

我發現了這個問題。我不知道爲什麼激活外的瀏覽器,然後回去需要這一點,但增加了ClientAccessPolicy.xml文件到名.web項目

<?xml version="1.0" encoding="utf-8"?> 
<access-policy> 
    <cross-domain-access> 
    <policy> 
     <allow-from http-request-headers="SOAPAction"> 
     <domain uri="*"/> 
     </allow-from> 
     <grant-to> 
     <resource path="/" include-subpaths="true"/> 
     </grant-to> 
    </policy> 
    </cross-domain-access> 
</access-policy> 

解決了這一問題。

0

例如,嘗試在Application_Unhan進入下面一行App.Xaml.cs的dledException方法(App.Xaml的代碼隱藏) 「MessageBox.Show(e.ExceptionObject.Message);」。這可以讓你知道當調試器還沒有連接到瀏覽器時出了什麼問題。購買方式在Visual Studio中,您可以在調試菜單 - >附加到進程...中手動將調試器附加到瀏覽器,然後選擇類型爲「Silverlight,x86」的進程。

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
    { 
     MessageBox.Show(e.ExceptionObject.Message); 
     // If the app is running outside of the debugger then report the exception using 
     // the browser's exception mechanism. On IE this will display it a yellow alert 
     // icon in the status bar and Firefox will display a script error. 
     if (!System.Diagnostics.Debugger.IsAttached) 
     { 

      // NOTE: This will allow the application to continue running after an exception has been thrown 
      // but not handled. 
      // For production applications this error handling should be replaced with something that will 
      // report the error to the website and stop the application. 
      e.Handled = true; 
      Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); 
     } 
    } 
相關問題