title: ASP.NET Core cannot find cshtml file by path using RazorViewEngine
body: <p>I want to find my <code>cshtml</code> file in my ASP.NET Core 2.1 Web API project. To do it, I'm using this code:</p>
  
  <pre><code>var httpContext = new DefaultHttpContext { RequestServices = this.serviceProvider };
  var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
  
  var viewResult = this.razorViewEngine.FindView(
                  actionContext,
                  "~/PdfTemplate/ProjectRaport.cshtml",
                  false);
  </code></pre>
  
  <p>The file is here:</p>
  
  <p><a href="https://i.stack.imgur.com/EFhsm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EFhsm.png" alt="enter image description here"></a></p>
  
  <p>But from code above, the <code>View</code> (that is <code>~/PdfTemplate/ProjectRaport.cshtml</code>) is null. </p>
  
  <p>How to find specific file by path in <code>WebApi Core</code>?</p>
  
  <p>This code works ok:</p>
  
  <pre><code>var viewResult = this.razorViewEngine.FindView(actionContext,
                  Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
                  false);
  </code></pre>
  
  <p>Path to file is ok, but the <code>View</code> in <code>viewResult</code> is still null</p>
  
  <p>When I tried <code>GetView</code>:</p>
  
  <pre><code>var viewResult = this.razorViewEngine.GetView(
                  Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
                  Path.Combine(this.hostingEnvironment.ContentRootPath, "PdfTemplate", "ProjectRaport.cshtml"),
                  false);
  </code></pre>
  
  <p>the <code>viewResult.View</code> is still null</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>In <code>SearchedLocations</code> the path is ok:</p>
  
  <p><a href="https://i.stack.imgur.com/zkR69.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zkR69.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/lsYBX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lsYBX.png" alt="enter image description here"></a></p>
  
  <p>When I deleted <code>.cshtml</code> extension, <code>SearchedLocations</code> is empty</p>