2011-07-12 242 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); }); 
     } 
    } 
相关问题