Error - hyperlink in a WBA in an IFrame

I have a hyperlink in a WBA which is hosted in an IFrame. The hyperlink is pointing to an HTML page. When I click on it, an error is raised right before the WBA exists and the browser is redirected to the HTML page.

The error is here:
http://www.valil.com/AmazonBookInfo/error.jpg
I have created a sample project to recreate the error:
http://www.valil.com/AmazonBookInfo/TestHyperlinkIFrame.zip
(double-click on index.html from bin\Debug and then click on the hyperlink)

The error shows up only if the WBA is in the IFrame - if it is loaded by itself it works OK.

Thank you,
Valentin Iliescu





Answer this question

Error - hyperlink in a WBA in an IFrame

  • lvance

    My version of WinFX is Sep 2005 CTP. I get this error on both Windows XP SP2 and Windows 2003 Server SP1.

    Can you try my Amazon ads ( http://www.valil.com/winfx/ads.html ) to see if you get the error It happens when you click on a book link and the browser is redirected to Amazon's website.

    Thank you,
    Valentin


  • viperjason

    Yes, the error doesn't show up if I move the mouse away after clicking.

    Thank you,
    Valentin

  • Francy

    It makes sense ... Thank you for your help. I think I will wait for the next CTP (Beta 2 ).

    Valentin


  • Tamoxifeno

    I have tried as you said - I get the same error.

    To clarify what I have tried:

    1. First variant:
    MyHyperlink.xaml.cs
    public
    partial class MyHyperlink : Hyperlink{
    public
    MyHyperlink(){InitializeComponent();}
    protected
    override void OnMouseEnter(MouseEventArgs e){}
    protected
    override void OnMouseLeave(MouseEventArgs e){}
    }

    MyHyperlink.xaml:
    <Hyperlink x:Class="MyNamespace.MyHyperlink"
    xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
    xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"/>

    2. Second variant:
    MyHyperlink.cs
    public class MyHyperlink : Hyperlink
    {
            protected override void OnMouseEnter (MouseEventArgs e) { }
            protected override void OnMouseLeave(MouseEventArgs e) { }
     }

    In both cases the control has been referenced like this:
    < Mapping XmlNamespace="controls" ClrNamespace="MyNamespace" >
    <StackPanel ... xmlns:c="controls" ... >
    <TextBlock >
            <c:MyHyperlink x:Name="titleLabel" NavigateUri=""/>
      </TextBlock>

    It seems like subclassing Hyperlink makes the code to request Unrestricted=true for UIPermission



  • CarlM

    I did as you have said but know there is another problem - now I get this error when I run the WBA:
    "Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    It is because of subclassing Hyperlink, I did it like this:
    C#:
    public
    partial class MyHyperlink : Hyperlink{
    public MyHyperlink()
    {
    InitializeComponent();
    }

    protected override void OnMouseEnter(MouseEventArgs e){}

    protected override void OnMouseLeave(MouseEventArgs e){}

    }
    XAML:
    <Hyperlink x:Class="Valil.AmazonBook.VisualElements.MyHyperlink"
    xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
    xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"/>



  • Sri Dendi

    Thank you very much for reporting this error. I cannot reproduce it with the latest version of Avalon (pre-Beta2). What is your version We may be able to suggest a workaround, if you need this setup to work.

  • patti_nyl

    I was not able to repro with PDC bits on IE7.  (Both your Amazon app and the test repro succeeded.)  Are you on IE6 or IE7 < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

     

    Thanks,
    Karen


  • milTash

    Yes, you are right. It turns out Hyperlink has an inheritance demand. I am told it was added as a security mitigation--to be able to know for sure when a navigation is user-initiated. I had tried the workaround, but in a full-trust app... Sorry about the misleading suggestion. At this point (before Beta 2), you can only try to replace your hyperlinks with either (styled) buttons or text formatted to look like hyperlinks...

  • Giusy Provvidenti

    Oh, you have attempted to use the "code-behind" model, but I think it is available only for select root-level elements. Here is how to define and use your derived class:



    namespace MyNamespace
    {
        public class MyHyperlink : Hyperlink
        {
            protected override void OnMouseEnter System.Windows.Input.MouseEventArgs e)
            {
            }
            protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
            {
            }
        };
    }

     


    In the XAML file:



            < Mapping XmlNamespace="my_namespace" ClrNamespace="MyNamespace" >
            <TextBlock xmlns:my="my_namespace">
                <my:MyHyperlink NavigateUri="...">Go to Start Page</my:MyHyperlink>
            </TextBlock>


     


    The Mapping and xmlns declarations can be in a higher scope. See the 'Custom Components' SDK topic for more explanation of this pattern.



  • ini686

    Awkward workaround (until Beta 2), if you really need it: Derive a class from Hyperlink that simply overrides OnMouseEnter() and OnMouseLeave() and doesn't call the base-class implementation. Use this class in your XAML definition instead. (You'll need a < Mapping > processing instruction. See example in the 'Custom Components' SDK topic.) The idea is to disable showing the hyperlink's target in the status bar, which is what leads to the failure you reported.

    Good luck. Smile

    [This posting is provided "AS IS" with no warranties, and confers no rights.]



  • Aleniko

    ...and it doesn't show up under IE 6 either (still Sept CTP). But we found a plausible explanation: timing issue on WBA shutdown. The failing Invariant Assert was actually removed in newer builds.

    Try moving the mouse away from the hyperlink as soon as you click it. If that prevents the error, it may suggest a possible workaround for your code.

    Thanks again for reporting the problem and doing it in such detail.

  • Error - hyperlink in a WBA in an IFrame