none
HtmlPage.Document and Safari 5

    General discussion

  • I have a silverlight 4 app that has been working fine and still works in MSIE 8/9 and FF 5. However, some Mac users started telling me that what used to work stopped working. So I installed Safari 5/5.1 and the SL app didn't work. However, if I change the user agent from Safari to MSIE or FF inside of Safari, the app works fine.

    So I put some try/catch logic in the code and found that whenever I tried to reference HtmlPage.Document, it would throw this error:

    Unable to cast object of type System.Windows.Browser.HtmlElement to type System.Windows.Browser.HtmlDocument

    The same thing happens when I try to access HtmlWindow - the error message then says HtmlWindow instead of HtmlDocument.

    This one line of code will cause the error:

    HtmlDocument heTemp = HtmlPage.Document; 
    
     

    Someone know what's going on?

     

    Wednesday, August 31, 2011 12:30 PM

All replies

  • I'm getting what looks to be the same thing with my SL 4 application.  It works fine on IE 7/8/9, Opera, Firefox, and Chrome, but on Safari for Windows, it will crash when trying to use the Silverlight Navigation.  More details:

    • It will crash on Safari for Windows on my Windows 7 machine, but NOT my Server 2008 machine.
    • The error message is:

     My error with Silverlight navigation in safari for windows

     

    I *don't think* it is occuring in Safari for Macs from what I've heard....

    You can test it out yourself by going to the website:

    http://www.murtaya.com/Murtaya.Web/MurtayaTestPage.html#/Home

     

    Any help is MUCH appreciated (I was always hoping Silverlight would work exactly the same in any supported browser).

    Thanks!

    Mike

    Monday, September 19, 2011 4:42 PM
  • I'm going to send that link to one of my mac users and see what happens. I'll post back when I know something.

    Monday, September 19, 2011 4:46 PM
  • Well, it worked just fine a someone's mac.

    Monday, September 19, 2011 4:53 PM
  • Thanks for checking...have you had any new information or break-throughs on this issue?

     

    I just had one of my friends test it on his Mac (Lion) and it worked fine for him.

    It's working fine on my Safari for Windows on Server 2008 RC1, but it's failing on my Safari for Windows on Windows 7...

    Thanks-

    Mike

    Monday, September 19, 2011 5:52 PM
  • I haven't a heard a word from anyone on this. Normally the lords of MSFT eventually weigh in, but not so far.

    Tuesday, September 20, 2011 9:14 AM
  • Should I create a bug?

    Tuesday, September 20, 2011 4:20 PM
  • GFI

    Wednesday, September 21, 2011 5:41 AM
  • I was unable to Repro using...

     

    Mac OS X (10.6.8)

    Safari 5.1 (6534.50)

     

    With the following code.

     

    void MainPage_Loaded(object sender, RoutedEventArgs e)

            {

               
    HtmlDocument heTemp = HtmlPage.Document;

     

               
    if (heTemp != null)

                   
    MessageBox.Show("Yay!");

               
    else

                   
    MessageBox.Show("Nay!");

            }

     

    If you can provide more details on How to Repro, I suggest
    you file a bug on https://connect.microsoft.com/VisualStudio
    or Contact Microsoft Developer Support.

    Thursday, September 22, 2011 9:33 AM
  • So you didn't try safari 5.1 on windows?

    Thursday, September 22, 2011 9:49 AM
  • No. Your original post stated the issue was on Macs, so that's what was tested. From a support perspective we've reached a point where continuing is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a support case with us. Visit this link to see the various support options that are available to better meet your needs:  http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone. If this turns out to be a bug, it's free of charge, of course.

    Monday, September 26, 2011 3:43 PM
  • Well, actually I specifically mentioned that I tested Safari under WINDOWS, not on a mac. However, I just thought someone at MSFT would like to know that there is a problem. But it is probably an apple bug, not silverlight. In any case, I'm sure it only affects a small fraction of all the users out there. And it will eventually be fixed by apple with the next point release, if they even care.

    Monday, September 26, 2011 3:56 PM
  •   I'm having the same problem. Safari 5.1.1 on Windows, a simple line of code like this:

     var element = HtmlPage.Window
    Will result in an error
    System.InvalidCastException: Unable to cast object of type 'System.Windows.Browser.HtmlElement to type 'System.Windows.Browser.HtmlWindow'
    
    
    Monday, November 21, 2011 7:58 PM
  • No help from the helpers.

    Tuesday, November 22, 2011 7:22 AM
  • Well, I can confirm this behaviour as well.

    Friday, January 13, 2012 5:52 AM
  • I have the same problem, it seems to only occur on Safari for Windows with the Silverlight plugin 5.0.61118.0.  The problem seems to have been introduced with Silverlight 5.0.

    Also, you cannot access: HtmlPage.Window

    According to Microsoft officially Safari for Windows is not a support platform, see:
    http://www.microsoft.com/getsilverlight/Get-Started/Install/Default.aspx (click System Requirements)

    I am pretty sure that it worked with Silverlight 4 (as is this original poster) but I cannot find the runtime anywhere as Microsoft seems only to allow v5 for download, can anyone provide a link to Silverlight 4 runtime?

    I will raise a case with Microsoft.

    Monday, January 16, 2012 7:03 PM
  • This issue exists in both Silverlight 4 and Silverlight 5.  The word I have is that because it's not a supported platform, it won't be fixed, unfortunately.

    Thursday, January 19, 2012 4:20 AM
  • In my testing I found that the issue does NOT occur in Silverlight 4 but DOES occur in Silverlight 5.

    This is slightly confused because if you try to install Silverlight 4 on Safari for Windows from this link:

    http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0

    Then you end up with a Silverlight 5 installation.

    I found that you use IE to visit this link then Save the download EXE, then install the EXE on Safari for Windows you will get a Silverlight 4 install and from my testing this works.  Thus, I am advising my customers who face this issue to install Silverlight 4 as described.

    Monday, January 23, 2012 10:35 AM
  • I am hitting the same bug!  This reply is pissing me off!

    Thursday, March 01, 2012 1:59 AM
  • Try this and see if this works(my application uses the navigation framework):

    As the error has something to do with the NavigationJournal and in SL we have some control over it I just changed the Journal ownership to

    <sdk:Frame JournalOwnership="OwnsJournal"

    On the MainPage.xaml where the naviogation takes place in my app. In this way we lose the browsers back button/navigation but we can implement our own inside the sl app.

    Wednesday, March 14, 2012 11:39 AM
  • Hey all,

    Just wanted to say I've been debugging a similar issue today and it's definitely the Silverlight plugin causing all the errors you've listed - because if you change your Safari user agent to any other supported browser, it works fine!! Beggars belief...

    Currently our work-around is to get users to change their user agent string, but we're investigating some manual way to override the silverlight user-agent sniffing. I'll report back if I make any progress.

    *Edit for clarity* I'm talking about issues with Silverlight 5 running in Safari 5.1.4 on Windows 7 - I can't yet speak for other combinations.

    Friday, March 16, 2012 8:06 AM
  • I'm having the same issue; Ridiculous really.

    Monday, May 07, 2012 10:59 PM
  • Spectacularly epic fail by our dark overlords.

    Tuesday, May 08, 2012 3:56 AM
  • Same issue here. Microsoft, please, fix this bug!!!

    Friday, May 11, 2012 12:09 PM
  • No one from MS is chiming in?  Same issue here, Silverlight 4 -  running code:

    HtmlPage.Window.Navigate(new Uri("http://www.anywhere.com"));

    Throws exception:   Unable to cast object of type 'System.Windows.Browser.HtmlElement' to type 'System.Windows.Browser.HtmlWindow'.

    greeeeaaaaatttt. 

    Tuesday, July 24, 2012 11:33 PM
  • Yup - almost 11 months and counting...

    Tuesday, July 24, 2012 11:45 PM
  • LOL Microsoft.  So I cannot allow my users to do any kind of page redirect while using Safari on windows... haha, I could maybe see if it was on MAC, but your own OS, classic MS.  I guess this complaining is futile, as it is obvious they are not monitoring this thread anymore. Lets keep it alive!!

    Tuesday, July 24, 2012 11:55 PM
  • I think if you read their documentation carefully, Windows Safari isn't supported for silverlight. Still, it would be nice to know what gives.

    Tuesday, July 24, 2012 11:59 PM
  • Yeah on the surface it makes it sound like it is supported, but if you dig in it says Safari and even Chrome i think are not fully supported. From what I am reading silverlight isn't going to be the Flash replacement they wanted, good thing I havn't learned too much about it, just using it on this one project. Thanks

    Wednesday, July 25, 2012 1:56 PM
  • My last 2 cents here for people looking for a solution to this. Basically do not allow your users to use Safari on Windows. Add an error handler for this specific error and then show an ERROR pop out window or whatever it is called in Silverlight. in the error just say "This application does not work with Safari on Windows please use FF or IE, etc".  good luck

    Wednesday, July 25, 2012 2:01 PM
  • 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. The challenge for me was that our SL page needs to immediately make a HTTP request to get data after the main control has 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(() =>
                {
    ....
    }

    Friday, May 03, 2013 6:52 PM