You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
Since updating to 2.0 I have noticed my DisplayTemplates that are loaded into a String via FindView are no longer able to find the View when in production where the pre-compiled views has been defaulted to on.
Details
The pre-compiled view option enabled by default does not include the source views when publishing (obviously) so it appears the IRazorViewEngine.FindView is unable to locate the view in the DLL.
This may not be unique to 2.0 but more to do with the default pre-compiled views being switched on and until now not something I had enabled manually.
var engine = _serviceProvider.GetService(typeof(IRazorViewEngine)) as IRazorViewEngine;
var tempDataProvider = _serviceProvider.GetService(typeof(ITempDataProvider)) as ITempDataProvider;
if (engine == null) throw new Exception("Can't find IRazorViewEngine");
var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
var viewEngineResult = engine.FindView(actionContext, name, false);
if (!viewEngineResult.Success)
{
throw new InvalidOperationException(string.Format("Couldn't find view '{0}'", name));
}
Expected Behaviour
I would expect the ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage) method to be able to locate the view in the pre-compiled views DLL and output in the same way as if it was not pre-compiled.
Thanks,
David
The text was updated successfully, but these errors were encountered:
Your expectations are correct, the view engine should discover the precompiled view. What's the value you're attempting to pass in to FindView. Your might be running in to #6672.
The view name I am passing in is Shared/DisplayTemplates/ContentCard which is located in /Views/Shared/DisplayTemplates/ContentCard.cshtml
I have tried using paths like /Views/Shared/DisplayTemplates/ContentCard.cshtml, /Views/Shared/DisplayTemplates/ContentCard and ~/Views/Shared/DisplayTemplates/ContentCard.cshtml and other permutations of this that I could think of without luck.
Simply disabling pre-compiling the views on deployment resolves the issue but we obviously lose the benefit of that process.
Issue
Since updating to 2.0 I have noticed my DisplayTemplates that are loaded into a String via FindView are no longer able to find the View when in production where the pre-compiled views has been defaulted to on.
Details
The pre-compiled view option enabled by default does not include the source views when publishing (obviously) so it appears the IRazorViewEngine.FindView is unable to locate the view in the DLL.
This may not be unique to 2.0 but more to do with the default pre-compiled views being switched on and until now not something I had enabled manually.
Expected Behaviour
I would expect the
ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
method to be able to locate the view in the pre-compiled views DLL and output in the same way as if it was not pre-compiled.Thanks,
David
The text was updated successfully, but these errors were encountered: