简体   繁体   中英

Multiple errors on _Layout.cshtml in ASP Core

I have an ASP Core application. It builds and runs without any problems but Visual Studio is showing lots of errors:

| Severity  |  Code    |  Description                                                                                                                   |    Project File                  |
|-----------|----------|--------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| Error     |  CS0234  |  The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)           |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'Helpers' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)    |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)   |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)   |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)   |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0115  |  '_Page_Views_Shared__Layout_cshtml.Execute()': no suitable method found to override                                           |    1_Views_Shared__Layout.cshtml | 
| Error     |  CS0103  |  The name 'Context' does not exist in the current context                                                                      |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0103  |  The name 'ViewData' does not exist in the current context                                                                     |    1_Views_Shared__Layout.cshtml |

The _Layout.cshtml file is the default one:

<!DOCTYPE html>

<html>
<head>
    <title>BanksySan @ViewData["Title"]</title>
</head>
<body>
<div>

</div>
</body>

The only think different about this project is that it's been built up from a console application, rather than via the web template.

I have the following package references:

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
   <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="1.1.3" />
   <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
   <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
   <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
   <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.1" />
   <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
   <PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
   <PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
   <PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>

This to me is usually the case when Visual Studio was not able to load the basic require package such as system

A) try to clean do a dotnet restore on the project folder B) if that didn't work clean nuget cache folder and run again C) Close visual studio and reboot and clean again. it is also possible you have a zombie process that is still running that is not allowing visual studio to to access its temporary folder. D) copy project to new path (git clone if possible) and to a fresh dotnet restore

I even had this error in Ride and above four helped me to get rid of it.

I hope it helps Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM