This project is read-only.

Period in Area name causes major problems

Topics: Troubleshooting, Writing modules
Mar 7, 2011 at 9:40 PM

Whilst creating a module I accidentally put a period in the Area name in routes and in some of the .cshtml files for forms.

This caused havoc and took a while to find the cause of the problem.

Errors included

(i) the dreaded error "Value cannot be null. Parameter name: serviceKey" which several people here seem to have experienced
(ii) admin menus that didn't go anywhere (they had an empty href parameter)

The code to render the menu Url in NavigationManager.cs starts like this:-

       public string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDictionary) {
            var url = string.IsNullOrEmpty(menuItemUrl) && (routeValueDictionary == null || routeValueDictionary.Count == 0)
                          ? "~/"
                          : !string.IsNullOrEmpty(menuItemUrl)
                                ? menuItemUrl
                                : _urlHelper.RouteUrl(routeValueDictionary);

Unfortunately when passed a routeValueDictionary containing an area name like "" UrlHelper returns a null.

Whilst we probably wouldn't want Orchard to stop the page from rendering when this happens (because one bad module could crash the system), it would be nice to know from at least an error log that something had gone wrong.

Suggest that url is checked after this statement and if it's still null log an error message dumping the route values that caused the problem along with the message.

            if (url == null && routeValueDictionary != null)
                log.Warn("Failed to get url for " + string.Join(" ", routeValueDictionary.Select(x => x.Key + " = " + x.Value)));

And for anyone experiencing the message above, make sure your area names don't have periods in them!

Mar 7, 2011 at 9:51 PM

You should probably file a bug but this sounds weird as most of our own modules/areas are named Orchard.Something.

Mar 7, 2011 at 10:15 PM

True, so how do they get through UrlHelper.RouteUrl without problem but mine come back with a null?

And, in particular, how does area = Orchard.Packaging action = Modules controller = Gallery result in an url of /Packaging/Gallery/Modules ?

Where is the "Orchard." getting stripped out?

Mar 7, 2011 at 10:34 PM

There has been a recent change in how default urls are handled. Previously it was using the Name from the manifest. It occured that if this name had a space, it would not work. Thus the Id is taken by default now, and if a Path property is defined it will be taken.

Mar 7, 2011 at 10:37 PM

I think in StandardExtensionRouteProvider.