title: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'
body: <p>I've created a project using the Visual Studio <em>.NET Core 2.1 SDK + React Template</em>.</p>
  
  <p>I'm met with the following error when running the project:</p>
  
  <blockquote>
    <p>One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false.</p>
  </blockquote>
  
  
  
  <blockquote>
    <p>The type or namespace name 'Hosting' does not exist in the namespace 
    'Microsoft.AspNetCore.Razor' (are you missing an assembly reference?)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/gCRiG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gCRiG.png" alt="enter image description here"></a></p>
  
  <p>I've done what research I could and have tried the following to no avail:</p>
  
  <ul>
  <li><code>dotnet restore</code> in Package Manager Console</li>
  <li>Deleting my <code>bin</code> and <code>obj</code> folders</li>
  <li>Opening <code>_ViewImports.cshtml</code> and adding a <code>@using</code> for <em>every namespace in my solution</em></li>
  </ul>
  
  <p>If I modify the <code>HomeController Index()</code> from returning the <code>View()</code> to instead <code>[HttpGet] public string Index() =&gt; "Hello World!";</code>, the text is returned without any error.</p>
  
  <hr>
  
  <p><strong>Index.cshtml</strong></p>
  
  <pre><code>@{
      ViewData["Title"] = "Home Page";
  }
  
  &lt;div id="react-app"&gt;Loading...&lt;/div&gt;
  
  @section scripts {
      &lt;script src="~/dist/main.js" asp-append-version="true"&gt;&lt;/script&gt;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>HomeController.cs</strong></p>
  
  <pre><code>using System.Diagnostics;
  using Microsoft.AspNetCore.Mvc;
  
  namespace sample_project.Controllers
  {
      public class HomeController : Controller
      {
          public IActionResult Index()
          {
              return View();
          }
  
          public IActionResult Error()
          {
              ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
              return View();
          }
      }
  }
  </code></pre>