Closed sebastianbk closed 7 years ago
@sebastianbk this is a variant of https://github.com/aspnet/Mvc/issues/6672. Essentially the PhysicalFIleProvider
does some additional work with path resolution which we don't currently do as part of precompiled views (or EmbeddedFileProvider
). I detailed your problem here: https://github.com/aspnet/Mvc/issues/6672#issuecomment-324433489
For the time being, here's my recommended workaround:
Modify RenderToStringAsync
to use GetView
in addition to FindView
to resolve views. This is essentially what Mvc does when you do return View()
. See https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs#L79-L84 for the pattern to use. I'm planning on updating our sample for views -> string today to show the right pattern (https://github.com/aspnet/Entropy/issues/260).
Pass in a path to RenderToStringAsync
. So you have RenderVIewToString("/Views/Models/_InputRow.cshtml")
.
If you'd like to keep your implementation of IViewRenderService
as is, you could register a IViewLocationExpander
that injects a search location without the controller: /Views/{0}.cshtml
,
Closing because this is covered by https://github.com/aspnet/Mvc/issues/6672.
And I thought I'm going nuts... Thank you for opening and tracking this issue.
Ever since upgrading from ASP.NET Core 1.1 to 2.0 I have been running into a bunch of weird issues that I can only reproduce in production and not on my local dev environment. This latest issue is related to
RazorViewEngine
and, when using it to render a partial view, it complains that it cannot find the view.This problem only occurs when running in production. When I am running the exact same code locally on IIS Express (with Visual Studio 2017 v15.3), it works as intended.
Please see the application logs and the stack trace, which I pulled from my Azure App Service log stream.
The exception is being thrown in a class I made inspired by this blog post. When I was running ASP.NET Core 1.1, this worked well in production. So I am really confused about why this is happening, especially when considering I can't reproduce it locally.
I checked up on the docs on Razor view compilation and tried setting
MvcRazorCompileOnPublish
tofalse
. This fixed the issue but it is not really a fix I am happy with. How come partial views aren't included in the implicit precompiling when publishing?