Question

So this is a little strange. I have a VERY simple sitemap (reduced to this simplicity for debugging -- live version is much more complex):

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="false">
  <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
    <mvcSiteMapNode title="Why Buy Your New Home" Controller="WhyBuyYourNewHome" Action="Index" />
  </mvcSiteMapNode>
</mvcSiteMap>

When I try to load the page, I get the following error:

An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

Line 75:             else
Line 76:             {
Line 77:                 returnValue = UrlHelper.Action(action, controller, new RouteValueDictionary(routeValues));
Line 78:             }
Line 79: 


Source File: C:\sitemap\Branches\3.0.0\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapNodeUrlResolver.cs    Line: 77 

The strange this is that if I remove the "Why Buy Your New Home" node, it works. Also, the following works just fine and loads all of my dynamic nodes:

    <?xml version="1.0" encoding="utf-8" ?>
    <mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
      <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
        <mvcSiteMapNode title="Find Your New Home" controller="FindYourNewHome" action="Index">
          <mvcSiteMapNode title="Markets" action="Market" updatePriority="Critical" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapMarketNodeProvider, MyProject.MVC.Extensions">
            <mvcSiteMapNode title="Communities" action="Community" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapCommunityNodeProvider, MyProject.MVC.Extensions">
              <mvcSiteMapNode title="Driving Directions" action="DrivingDirections" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapDrivingDirectionsNodeProvider, MyProject.MVC.Extensions" />
              <mvcSiteMapNode title="Floorplans" action="Floorplan" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapFloorplanNodeProvider, MyProject.MVC.Extensions" />          
            </mvcSiteMapNode>
          </mvcSiteMapNode>
        </mvcSiteMapNode>
      </mvcSiteMapNode>
</mvcSiteMap>

It only seems to be when I add in very simplistic nodes that I'm getting this duplicate key error, yet if you look at my first XML sample, there's no duplicate key possible. If I add that "Why Buy Your New Home" node to my the last XML sample that includes the dynamic node providers, it breaks again. Any help on this one?

Was it helpful?

Solution 2

So it ended up being the fact that I had capitalized "Controller" and "Action" attributes in the XML. That was causing all nodes to fall to my "catchall" route so technically all of my site map nodes matched a single route.

Grrr....

OTHER TIPS

This most likely means the URL is the same for that WhyBuy node and some other url. Maybe you could post your routing?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top