[FIXED] Xamarin Shell Raise Ambiguous Routes matched Exception

Issue

In Xamari.Forms, I use the following route declaration in AppShell.xaml :

 <FlyoutItem Title = "Toolbox"
             FlyoutDisplayOptions="AsMultipleItems"
             Route="Main">

      <ShellContent Title = "Toolbox"
                    ContentTemplate="{DataTemplate Views:Toolbox}"
                    Route="Toolbox"/>

 </FlyoutItem>

 <ShellContent Title = "Parameters"
               ContentTemplate="{DataTemplate Views:Parameters}"
               Route="Parameters"/>

In the AppShell.xaml.cs, I add programatically a contextual page navigation for the Toolbox page:

public AppShell ()
{
    InitializeComponent ();

    Routing.RegisterRoute("Toolbox/TBOuvriers", typeof(TBOuvriers));

    BindingContext = this;
}

When I try to display the contextual page navigation from the Toolbox Page:
await Shell.Current.GoToAsync(“//Main/Toolbox/TBOuvriers”);

I get this Exception :

System.ArgumentException: Ambiguous routes matched for: //Main/Toolbox/TBOuvriers matches found:
//Main/Toolbox/TBOuvriers/TBOuvriers,
//Main/IMPL_Toolbox/Toolbox/TBOuvriers
Parameter name: uri

Just before the call, I can see those values for the Shell variables :
Shell.Current.CurrentItem : “Title = Toolbox, Route = Main”
Shell.Current.CurrentState.Location : “{//Main/Toolbox}”

Which seem to be the expected one’s.

If I try to display the page with this call:
await Shell.Current.GoToAsync(“TBOuvriers”);
I also get an Exception : System.Exception: Timeout exceeded getting exception details

So, What’s the problem ?
Where does those routes come from ?!?
Why is the Toolbox page 2 times registered ?

All ideas are welcome !

Best regards

Solution

For anyone that will face this issue, and have this error message too;

System.ArgumentException: ‘Ambiguous routes matched for: …’

This occures when you register your routes in XAML (in the appshell file) and you also try registering your routes in code behind in C#.
Only register your routes once using either XAML or C# not both.

Answered By – Damien Doumer

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published