The property 'MasterLocationFormats' cannot be null or empty.

Jan 13, 2011 at 12:46 PM

Hi all, I am getting the following error on certain pages since using MVC SiteMap:

The property 'MasterLocationFormats' cannot be null or empty.

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.InvalidOperationException: The property 'MasterLocationFormats' cannot be null or empty.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Anyone have any ideas what might be causing this?

Thanks

The property 'MasterLocationFormats' cannot be null or empty.

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.InvalidOperationException: The property 'MasterLocationFormats' cannot be null or empty.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Jan 13, 2011 at 2:44 PM

I had exactly the same problem when it was interacting with an extension I used to capture a View's output (it built an html email from a view, captured it, emailed it then returned a view). This took me a good part of a day to track down properly as it only happens once the helper has been called before but I was testing just on the page that had previously failed and the bug wasn't coming up.

The issue is with the MvcSiteMapProviderViewEngine which is registered as a second view engine when you use the menu helper. For most pages it was fine and MVC knew to only use the WebFormsViewEngine but the extension I used to capture output resulted in MVC trying to get the page using both ViewEngines, the MvcSiteMapProviderViewEngine doesn't have any MasterLocationFormats and it chucks up the error.

To fix it just replace the constructor with the following:

 public MvcSiteMapProviderViewEngine()
        {
base.ViewLocationFormats = new string[] { "~/__MVCSITEMAPPROVIDER/{0}.ascx" };
base.PartialViewLocationFormats = base.ViewLocationFormats;
base.AreaPartialViewLocationFormats = base.ViewLocationFormats;
base.MasterLocationFormats = base.ViewLocationFormats;
base.AreaMasterLocationFormats = base.ViewLocationFormats;
        }

this means there's location formats for the master page so MVC doesn't throw an exception but as it's used by the virtual path provider it won't pick any actual locations up and won't interfere with the rest of your application.

Coordinator
Jan 14, 2011 at 12:20 PM

Thanks for the patch!

Jan 17, 2011 at 3:33 PM

Thanks for the project :)