diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs
index fdb92a2f..97f49a55 100644
--- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs
+++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs
@@ -267,7 +267,7 @@ protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions
{
if (string.IsNullOrEmpty(assemblyNode.SiteMapNodeAttribute.ParentKey))
{
- throw new MvcSiteMapException(string.Format(Resources.Messages.NoParentKeyDefined, nodeToAdd.Controller, nodeToAdd.Action));
+ throw new MvcSiteMapException(string.Format(Resources.Messages.NoParentKeyDefined, this.siteMapCacheKey, nodeToAdd.Controller, nodeToAdd.Action));
}
var parentForNode = parentNode != null ? siteMap.FindSiteMapNodeFromKey(assemblyNode.SiteMapNodeAttribute.ParentKey) : null;
@@ -300,7 +300,7 @@ protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions
}
// Process list of nodes that did not have a parent defined.
- // If this does not succeed at this time, parent will default to root node.
+ // If this does not succeed at this time, an exception will be thrown.
if (parentNode != null)
{
foreach (var nodeToAdd in nodesToProcessLater)
@@ -308,11 +308,13 @@ protected virtual ISiteMapNode CreateNodesFromMvcSiteMapNodeAttributeDefinitions
var parentForNode = siteMap.FindSiteMapNodeFromKey(nodeToAdd.Value);
if (parentForNode == null)
{
- var temp = nodesToProcessLater.Keys.Where(t => t.Key == nodeToAdd.Value).FirstOrDefault();
- if (temp != null)
- {
- parentNode = temp;
- }
+ throw new MvcSiteMapException(
+ String.Format(
+ Resources.Messages.ReflectionSiteMapBuilderParentNodeNotFound,
+ nodeToAdd.Value,
+ this.SiteMapCacheKey,
+ nodeToAdd.Key.Controller,
+ nodeToAdd.Key.Action));
}
if (parentForNode != null)
{
diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.Designer.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.Designer.cs
index 5aca843c..1c708948 100644
--- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.Designer.cs
+++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.Designer.cs
@@ -214,7 +214,7 @@ internal static string NamedUrlResolverNotFound {
}
///
- /// Looks up a localized string similar to Multiple root nodes defined. Are you missing a ParentKey definition on the '{0}' controller, '{1}'?.
+ /// Looks up a localized string similar to Multiple root nodes defined in sitemap with cache key '{0}'. Are you missing a ParentKey definition on the '{1}' controller, '{2}' method?.
///
internal static string NoParentKeyDefined {
get {
@@ -249,6 +249,17 @@ internal static string PhysicalPathNotAllowed {
}
}
+ ///
+ /// Looks up a localized string similar to The parent node with key '{0}' was not found in the sitemap with cache key '{1}' for the MvcSiteMapNodeAttribute defined on '{2}' controller, '{3}' method. The most likely cause is that the key property for the parent node was not set explicitly in your node configuration or it does not match the ParentKey that was set on '{2}' controller, '{3}' method.
+ ///
+ ///This error can also happen if the 'Order' property for MvcSiteMapAttribute definitions has not been specified. Be sure the 'Order' for each parent node i [rest of string was truncated]";.
+ ///
+ internal static string ReflectionSiteMapBuilderParentNodeNotFound {
+ get {
+ return ResourceManager.GetString("ReflectionSiteMapBuilderParentNodeNotFound", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to There is more than one MvcSiteMapNodeAttribute declared without a parent key. The ParentKey property must be set for all (or all but 1) MvcSiteMapNodeAttribute in the application..
///
diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.resx b/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.resx
index 505256f6..9be1271b 100644
--- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.resx
+++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Resources/Messages.resx
@@ -142,7 +142,7 @@
Multiple nodes with the same URL '{0}' were found. SiteMap requires that sitemap nodes have unique URLs.
- Multiple root nodes defined. Are you missing a ParentKey definition on the '{0}' controller, '{1}'?
+ Multiple root nodes defined in sitemap with cache key '{0}'. Are you missing a ParentKey definition on the '{1}' controller, '{2}' method?
The URL resolver instance named '{0}' was not found. Check your DI configuration to ensure a URL resolver instance with this name exists and is configured correctly.
@@ -223,4 +223,9 @@ PreservedRouteParameters always copies the route value from the current HTTP req
Alternatively, if you are configuring the node in XML and intend to use '{1}' as a custom attribute, use the 'MvcSiteMapProvider_AttributesToIgnore' configuration setting to ensure '{1}' is not automatically added to RouteValues. If using external DI, this setting is injected into the constructor of 'SiteMapXmlReservedAttributeNameProvider'.
+
+ The parent node with key '{0}' was not found in the sitemap with cache key '{1}' for the MvcSiteMapNodeAttribute defined on '{2}' controller, '{3}' method. The most likely cause is that the key property for the parent node was not set explicitly in your node configuration or it does not match the ParentKey that was set on '{2}' controller, '{3}' method.
+
+This error can also happen if the 'Order' property for MvcSiteMapAttribute definitions has not been specified. Be sure the 'Order' for each parent node is lower than the 'Order' for its child nodes.
+
\ No newline at end of file