Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在浏览器应用程序中启用浏览器外Silverlight中断_C#_Silverlight_Out Of Browser - Fatal编程技术网

C# 在浏览器应用程序中启用浏览器外Silverlight中断

C# 在浏览器应用程序中启用浏览器外Silverlight中断,c#,silverlight,out-of-browser,C#,Silverlight,Out Of Browser,我目前正在Silverlight中开发一个小应用程序,最近为了试用,我为我的应用程序启用了浏览器外部署。但是,现在在我禁用设置之后,运行应用程序现在会在加载完成后立即抛出异常 silverlight应用程序中的未处理异常“未处理错误” 代码:4004 类别:ManagedRuntimeError 消息:System.Reflection.TargetInvocationException:操作期间发生异常,导致结果无效 但是,如果我只是在浏览器中打开TestPage.html,应用程序仍然可以正

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

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

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


有什么想法吗?谢谢

例如,尝试在App.Xaml.cs的Application\u UnhandledException方法中输入App.Xaml的代码 MessageBox.Showe.ExceptionObject.Message;。这可以让您了解当调试器尚未连接到浏览器时会出现什么问题。按照这种方式,在VisualStudio中,您可以在debug菜单->attach to Process…(附加到进程…)中将调试器手动附加到浏览器,然后选择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); });
        }
    }

例如,尝试在App.Xaml.cs的Application_UnhandledException方法中输入以下行,以删除App.Xaml的代码 MessageBox.Showe.ExceptionObject.Message;。这可以让您了解当调试器尚未连接到浏览器时会出现什么问题。按照这种方式,在VisualStudio中,您可以在debug菜单->attach to Process…(附加到进程…)中将调试器手动附加到浏览器,然后选择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); });
        }
    }

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

修复了问题。

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

修复了问题。

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