The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'



Trying to teach myself some new tools, but I've managed to break my project.



The solution is about a day old and consists of two projects. One is the application (created using the Visual Studio .NET Core 2.1 SDK + React Template), and the other is the data layer (which is just a Models folder).


Models



The data layer was implemented today, and that's when things got rocky. I don't want to point the finger there immediately, because it could've happened with some other changes I was making at the same time.



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.



The type or namespace name 'Hosting' does not exist in the namespace
'Microsoft.AspNetCore.Razor' (are you missing an assembly reference?)



enter image description here



I've done my fair share of research and cannot resolve this issue. I've tried...


dotnet restore


bin


obj


_ViewImports.cshtml


@using



If I modify the HomeController Index() from returning the View() to instead [HttpGet] public string Index() => "Hello World!";, the text is returned without any error.


HomeController Index()


View()


[HttpGet] public string Index() => "Hello World!";



Index.cshtml


@{
ViewData["Title"] = "Home Page";
}

<div id="react-app">Loading...</div>

@section scripts {
<script src="~/dist/main.js" asp-append-version="true"></script>
}



HomeController.cs


using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;

namespace world_cup_pools.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}

public IActionResult Error()
{
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View();
}
}
}




1 Answer
1



Shortly after posting this I've solved the issue.



I had upgraded my project to .NET Core 2.1 but one of the references (Microsoft.AspNetCore.All) was version 2.0.8.


Microsoft.AspNetCore.All


2.0.8



Upon updating this to 2.1.0, the project now works as expected.


2.1.0





thanks, was getting pretty nervous
– Elger Mensonides
Jul 2 at 16:11





Thanks! I did something similar. I upgraded 'Microsoft.AspNetCore.All' from 2.0.8 to 2.0.9 and nothing warned me that I had to target Core 2.1.
– AbeyMarquez
yesterday






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results