开发者

Enabling Silverlight Out-of-browser breaks in-browser application

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 a开发者_运维知识库pplication 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


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); });
        }
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜