【问题标题】:Enabling Silverlight Out-of-browser breaks in-browser application启用 Silverlight 浏览器外中断浏览器内应用程序
【发布时间】:2011-07-12 12:55:05
【问题描述】:

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

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

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

有什么想法吗?谢谢

【问题讨论】:

  • 这很奇怪!您是否尝试过在 silverlight 代码的开头设置断点并查看是否可以找到失败的行?
  • 我做到了,并且在构造函数之后的 App.xaml.cs 中出现错误。我创建了一个新的 silverlight 项目并复制了所有的 .xaml 和 .cs,它又像往常一样工作了。仍然有兴趣找到问题。
  • 发布这个异常的InnerException。这才是真正的问题所在。
  • 尝试向 URI“(我的 wcf 服务)”发出请求时发生错误。这可能是由于试图以跨域方式访问服务而没有适当的跨域策略,或者策略不适合 SOAP 服务。您可能需要联系服务的所有者以公开跨域策略文件并确保它允许发送与 SOAP 相关的 HTTP 标头。此错误也可能是由于在 Web 服务代理中使用内部类型而未使用 InternalsVisibletoAttribute 属性。

标签: c# silverlight out-of-browser


【解决方案1】:

例如,尝试在 App.Xaml.cs 的 Application_UnhandledException 方法中输入以下行(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); });
        }
    }

【讨论】:

    【解决方案2】:

    我发现了问题。我不确定为什么激活浏览器外然后返回需要这个,但是将 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>
    

    解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多