views:

198

answers:

1

I'm baffled. My site randomly throws the following error:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: The partial view '/SiteUserMenu' could not be found. The following locations were searched:
/SiteUserMenu
   at System.Web.Mvc.HtmlHelper.FindPartialView(ViewContext viewContext, String partialViewName, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName)
   at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)

Most of the time, the site runs fine... sometimes it throws the above error, which makes no sense to me. If the partial view wasn't found, why would it not be able to find it sometimes?

The partial view is saved in a folder named "en" under the Shared folder (inside of the views folder). Here's how I render the view:

<% Html.RenderPartial(ViewData["lang"] + "/SiteUserMenu"); %>

ViewData["lang"] is set in my base controller, in the OnActionExecuting action, like so:

var l = (RouteData.Values["language"] != null) ? RouteData.Values["language"].ToString() : string.Empty;

if (string.IsNullOrEmpty(l))
    l = "en";

if (l.Contains("en"))
{
    IsEnglish = true;
    l = "en";
}
else
    l = "ja";

ViewData["lang"] = l.ToLower();
Language = l.ToLower();

Language and IsEnglish are properties of the base controller. The whole site uses them to maintain language selection and to make appropriate choices based on language. If language is not set, it will be set to "en". So ViewData["lang"] should always be available to my views.

Any reason why a partial view couldn't be found somtimes, while most of the time (I'm talking 90% of the time) it works fine?

+3  A: 

As the error points to 'The partial view '/SiteUserMenu' could not be found.' you can see that its not picking up the 'en'. I would suggest that the best place to start debugging is the ViewData["lang"]. See if you can produce steps to replicate the error everytime, then debug into your solution to see if ViewData["lang"] has been set whilst you are in the erroring Action method of your Controller.

David Liddle
thanks... perhaps the routes are letting something through? but the routine above should always set ViewData["lang"] to "en" no matter what... hmm...
Chad
Hmm, any reason why OnActionExecuting wouldn't get called?
Chad
I'm at a loss... from local dev box, OnActionExecuting ALWAYS fires... NEVER causing the problem I described. On my host it randomly doesn't seem to fire. The hosting is IIS 6, could this cause the issue?
Chad
Strange... my error logger always seems to log that error, even if it isn't what is throwing the exception... maybe I'm on to something. Thanks for posting your answer.
Chad