title: Rendering view to string in core 3.0: Could not find an IRouter associated with the ActionContext
body: <p><strong>What I want:</strong></p>
  
  <p>In my application, I want to use a template for my e-mails. Unfortunately code I used before in another project doesn't work anymore.</p>
  
  <p><strong>The error thrown:</strong></p>
  
  <pre><code>Could not find an IRouter associated with the ActionContext. 
  
  If your application is using endpoint routing then you can get a IUrlHelperFactory with dependency injection 
  and use it to create a UrlHelper, or use Microsoft.AspNetCore.Routing.LinkGenerator.'
  </code></pre>
  
  <p>I have no clue how to fix this because I can't find any way to inject the <code>IUrlHelper</code>. I'm unsure as to why this is even needed since it's not there in the view anyway.</p>
  
  <p><strong>The string rendering method:</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>public async Task&lt;string&gt; RenderToStringAsync(string viewName, object model)
  {
      var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };
      var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
  
      using (var sw = new StringWriter())
      {
          var viewResult = FindView(actionContext, viewName);
  
          if (viewResult == null)
          {
              throw new ArgumentNullException($"{viewName} does not match any available view");
          }
  
          var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
          {
              Model = model
          };
  
          var viewContext = new ViewContext(
                      actionContext,
                      viewResult,
                      viewDictionary,
                      new TempDataDictionary(actionContext.HttpContext, _tempDataProvider),
                      sw,
                      new HtmlHelperOptions());
  
          await viewResult.RenderAsync(viewContext); // Throws error &lt;&lt;&lt;
          return sw.ToString();
      }
  }
  </code></pre>