title: Why does the RenderAsync fail in ASP.NET Core 2.2 but work in Core 2.1?
body: <p>I'm trying to generate a PDF from HTML and I have a method that uses the <code>RenderAsync</code> method, it works with ASP.NET Core 2.1, but I need to use ASP.NET Core 3.0 in my project, but when I updated it to ASP.NET Core 3.0, <code>RenderAsync</code> failed and threw:</p>
  
  <blockquote>
    <p>object reference not set to an instance of an object</p>
  </blockquote>
  
  <pre><code>public async Task&lt;string&gt; Render&lt;TModel&gt;(string executingViewPath, string viewPath, TModel model)
  {
      var viewEngineResult = razorEngine.GetView(executingViewPath, viewPath, false);
  
      if (!viewEngineResult.Success)
      {
          throw new InvalidOperationException($"Couldn't find view {viewPath}");
      }
  
      var view = viewEngineResult.View;
  
      using (var output = new StringWriter())
      {
          var viewContext = new ViewContext();
          viewContext.HttpContext = httpContextAccessor.HttpContext;
          viewContext.ViewData = GetViewData(model);
          viewContext.Writer = output;
  
          // needed to downgrade to asp.net core 2.1, because render async failed in core 2.2
          await view.RenderAsync(viewContext);//error: object reference not set to an instance of an object.
  
          return output.ToString();
      }
  }
  </code></pre>