After getting NULLREF after upgrading to the SS 5.6, it took me some time to realise the changes on the RazorFormat API. Can you please change the code below?
public ViewEngineResult GetPageFromPathInfo(string pathInfo)
{
if (pathInfo.EndsWith("/"))
pathInfo += "default.cshtml";
var viewPath = "~/wwwroot".CombineWith(pathInfo);
if (!viewPath.EndsWith(".cshtml"))
viewPath += ".cshtml";
var viewEngineResult = ViewEngine.GetView("", viewPath,
isMainPage: viewPath == "~/wwwroot/default.cshtml");
if (!viewEngineResult.Success)
{
viewPath = PagesPath.CombineWith(pathInfo);
if (!viewPath.EndsWith(".cshtml"))
viewPath += ".cshtml";
viewEngineResult = ViewEngine.GetView("", viewPath,
isMainPage: viewPath == $"{PagesPath}/default.cshtml");
}
return viewEngineResult.Success
? viewEngineResult
: null;
}
This is in RazorFormat.cs. It will return NULL when a view is not found, but the calling code does not explain which view and also does not mention which paths are searched.
In the end the following method gives the actual NULLREF:
private ViewEngineResult FindView(IEnumerable<string> viewNames, out Dictionary<string, object> routingArgs)
{
routingArgs = null;
const string execPath = "";
foreach (var viewName in viewNames)
{
if (viewName.StartsWith("/"))
{
var viewEngineResult = GetPageFromPathInfo(viewName);
if (viewEngineResult.Success) // <-- NULLREF
return viewEngineResult;
viewEngineResult = GetRoutingPage(viewName, out routingArgs);
if (viewEngineResult.Success) // <-- NULLREF
return viewEngineResult;
}
else
{
foreach (var location in ViewLocations)
{
var viewPath = location.CombineWith(viewName) + ".cshtml";
var viewEngineResult = ViewEngine.GetView(execPath, viewPath, isMainPage: false);
if (viewEngineResult.Success) // <-- NULLREF
return viewEngineResult;
}
}
}
return null;
}
It would be awesome to know all paths searched and the name of the view that gives the error.