启用 Silverlight 浏览器外会破坏浏览器内应用程序

发布于 2024-11-19 18:28:27 字数 288 浏览 1 评论 0原文

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

未处理的异常('silverlight 应用程序中的未处理错误 代码:4004 类别:托管运行时错误 消息:System.Reflection.TargetInitationException:操作期间发生异常,导致结果无效。

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

有什么想法吗?谢谢

I am currently developing a small application in Silverlight, and recently to try it out, i enabled out-of-browser deployment for my application. However, now after I disabled the setting, running the application now throws an exception as soon as it finishes loading.

An unhandled exception ('Unhandled Error in silverlight application
Code: 4004
Category: ManagedRuntimeError
Message: System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.

However, if I just open the TestPage.html in browser the application still works as it did.

Any ideas? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-11-26 18:28:28

例如,尝试在 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); });
        }
    }

For example, Try entering the following line in the Application_UnhandledException method of App.Xaml.cs (the code-behind of the App.Xaml)
"MessageBox.Show(e.ExceptionObject.Message);". This could give you an idea what goes wrong when the debugger is not yet attached the browser. Buy the way, In Visual Studio you can attach the debugger manually to your browser in the debug menu -> Attach to Process..., then choose the process with type "Silverlight, x86" for example.

    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); });
        }
    }
关于从前 2024-11-26 18:28:28

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

解决了问题。

I found the problem. I'm not sure why activating out-of-browser and then going back required this, but adding a ClientAccessPolicy.xml file to the .web project

<?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>

fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文