2

我目前正在 Silverlight 中开发一个小型应用程序,最近为了试用它,我为我的应用程序启用了浏览器外部署。但是,现在在我禁用该设置后,运行应用程序现在一旦完成加载就会引发异常。

未处理的异常('silverlight 应用程序中的未处理错误代码:4004 类别:ManagedRuntimeError 消息:System.Reflection.TargetInvocationException:操作过程中发生异常,导致结果无效。

但是,如果我只是在浏览器中打开 TestPage.html,应用程序仍然可以正常工作。

有任何想法吗?谢谢

4

2 回答 2

0

例如,尝试在 App.Xaml.cs(App.Xaml 的代码隐藏)的 Application_UnhandledException 方法中输入以下行 “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); });
        }
    }
于 2011-07-12T17:06:52.313 回答
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>

解决了这个问题。

于 2011-07-19T14:38:17.237 回答