Reputation: 21
We recently upgraded to silverlight 5. We're getting following exception when running in safari 5 browser...
Unable to cast object of type 'System.Windows.Browser.HtmlElement' to type 'System.Windows.Browser.HtmlWindow'.
How do we resolve this issue?
Upvotes: 2
Views: 3541
Reputation: 117
Not sure if this going to be of help but the following workaround works for me using SL5 and all browsers on windows for my specific use case. We load the host page from another application which passes information on the query string. I was previously using
foreach (var key in HtmlPage.Document.QueryString.Keys)
to get hold of the query string keys and values and then process accordingly. As HtmlPage.Document is no longer cross browser, I tried all alternatives but ended up creating a .net type that could be called by Javascript (JS). When the host page loads, I use JS to extract the query string and pass that into the .net type.
To do this, in your host page add this:
<param name="onLoad" value="plugInLoaded"/>
and some JS:
<script type="text/javascript">
function plugInLoaded(sender) { // code to set values into your .net type }
</script>
The challenge for me was that our SL page needs to immediately make a HTTP request to get data after the main control is rendered. We are not using RIA Services. Most examples on MSDN for passing data from JS to .net, involves a button click. There was race condition whereby the JS code would set the value on the .net type after the SL controls had been rendered. Using the Dispatcher solved this problem.
Dispatcher.BeginInvoke(() => { // code to get the value from the .net type }
Upvotes: 0
Reputation: 3277
We recently got this, too. The first problem is that Safari is not on the official list of supported browsers, so even though it worked before it's not guaranteed to work again.
I'm guessing you're using a Silverlight Business Application with Navigation? Or, I believe any Business Application will reproduce this issue. The way I've fixed it (found from here) is to change the main content frame in MainPage.xaml (or your equivalent if you've changed it) to include the following:
<navigation:Frame JournalOwnership="OwnsJournal" ...
This breaks the navigation back and forth. We're going to play around a bit more and try to set this for ONLY safari, but this should at least get you going!
EDIT: Easily got it on safari only in code-behind:
if ( HtmlPage.BrowserInformation.UserAgent.Contains("Safari") )
{
ContentFrame.JournalOwnership = JournalOwnership.OwnsJournal;
}
Upvotes: 1