[c#] The type or namespace name 'System' could not be found

I have the following errors (and more) in all my views (*.cshtml) when opening my project in Visual Studio 2015 Professional.

Error CS0246 The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) Severity Code Description Project File Line

Error CS0518 Predefined type 'System.Object' is not defined or imported Severity Code Description Project File Line

Error CS0518 Predefined type 'System.String' is not defined or imported

I got these references:

<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Sitecore.Kernel, Version=7.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\Sitecore.Kernel.dll</HintPath>
</Reference>
<Reference Include="Sitecore.Mvc">
  <HintPath>N:\XXX\Sitecore.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Providers">
  <HintPath>N:\XXX\System.Web.Providers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />

I found some solutions saying that a mscorlib wasn't referenced.. but when I tried to add it it sayd that it's already there (even though I don't see it on the csproj file).

System.dll reference:

enter image description here

enter image description here

SOLUTION:

Managed the issue.. I had the build path set to a "c:...\bin" instead of "\bin". I believe this happened because I don't have any web.config in the root of the project, so VS didn't identify my project as a web project.

This question is related to c# asp.net-mvc-5 visual-studio-2015 .net-4.5

The answer is


Using VS Professional 2019, I was trying to run a downloaded solution from a Udemy class on selenium automation testing, and most of the projects had errors in the project references sections. I tried cleaning, rebuilding, closing VS. Then, in VS, when I right clicked on the solution in Solution Explorer and chose Manage Nuget Packages for Solution, there were 2 available updates: for MSTest.TestAdapter and MSTest.TestFramework, and when I installed those, the error messages on the references for all the projects went away, for the references to those, as well as for the references to System and System.Core.


If cleaning the solution didn't work and for anybody who see's this question and tried moving a project or renaming.

Open Package manager console and type "dotnet restore".


Try to

  1. Clean Solution
  2. Rebuild Solution

I had the same problem earlier when I tried to edit an open source project from the internet .

Solved it by just Cleaning the solution and rebuilding it .

Hope this helps.


I had to delete the bin and obj folders from each folder in order to resolve this.


i had to upgrade from visual studio 2017 to 2019. no other proposed solution here helped me, i installed and configured, rebooted every one here plus many other options from ms site.

my root cause was probably due to the fact the git repository developer used 2019 and i tried to clone the original git repo into ma 2017.


Follow these steps :

  1. right click on Solution > Restore NuGet packages
  2. right click on Solution > Clean Solution
  3. right click on Solution > Build Solution
  4. Close Visual Studio and re-open.
  5. Rebuild solution. If these steps don't initially resolve your issue try repeating the steps a second time.

Thats All.


Check the Target framework. changed target framework from .NET framework 4.6.1 to .NET framework 4.6 has worked for me.


right click you project name then open the properties windows. downgrade your Target framework version, build Solution then upgrade your Target framework version to the latest, build Solution .


For the folks that like me got here because they're trying to host aspnet.core mvc in a console application: The ONLY way I was able to solve this was by converting the .csproj to the new format and add the Sdk property to the Project tag on the very first line.

<Project Sdk="Microsoft.NET.Sdk.Razor">


For me it only happened in one project and I tried everything I found online and nothing seemed to help. I was ready to delete and recreate the project when after messing through the projects properties changing the .NET framework target from 4.7.2 to 4.8 fixed the issue. I changed it back to 4.7.2 later and the error is gone.

Hopefully this helps other users as well.


Unload project -> Reload project normally fixes this weird, Nuget related, error to me.


I've tried all answers above. For me works only removal and adding the reference again described in the following steps:

  1. Open 'References' under the project.
  2. Right click on 'System' reference.
  3. Click on 'Remove'.
  4. Right click on 'References'.
  5. Click 'Add Reference...'.
  6. From right menu choose an 'Assemblies',
  7. In a search field type 'System'.
  8. Choose 'System' from the list.
  9. Click 'Add' button.
  10. IMPORTANT: Restart the Visual Studio.

You can check the framework on which system was created and developed, and then changes the framework of your current solution to the old framework. You can do this by right click on the solution and then choose properties. In Application section you can change the framework.


Open Project References, I had lots of yellow warning triangles on the various packages. Click Add Reference, just doing that seems to get VS to refresh it references, and the yellow triangles disappeared and the errors from the code also.

You might have to do this in a few projects if your solution reference to other projects


Cleaning solution worked for me.

I would also advise to close and relaunch Visual Studio once doing so.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net-mvc-5

'router-outlet' is not a known element The type or namespace name 'System' could not be found How to get 'System.Web.Http, Version=5.2.3.0? EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType How to extend available properties of User.Identity How to implement oauth2 server in ASP.NET MVC 5 and WEB API 2 How to get JSON object from Razor Model object in javascript The model backing the 'ApplicationDbContext' context has changed since the database was created How can I implement a theme from bootswatch or wrapbootstrap in an MVC 5 project? MVC 5 Access Claims Identity User Data

Examples related to visual-studio-2015

How to download Visual Studio Community Edition 2015 (not 2017) The default XML namespace of the project must be the MSBuild XML namespace tsconfig.json: Build:No inputs were found in config file How to install Visual C++ Build tools? Could not load file or assembly "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" How to unapply a migration in ASP.NET Core with EF Core The term "Add-Migration" is not recognized Visual Studio 2015 Update 3 Offline Installer (ISO) Getting "project" nuget configuration is invalid error ASP.NET 5 MVC: unable to connect to web server 'IIS Express'

Examples related to .net-4.5

There is no argument given that corresponds to the required formal parameter - .NET Error The type or namespace name 'System' could not be found Which versions of SSL/TLS does System.Net.WebRequest support? async at console app in C#? Is it possible to run a .NET 4.5 app on XP? Awaiting multiple Tasks with different results Do you have to put Task.Run in a method to make it async? C# HttpClient 4.5 multipart/form-data upload Do HttpClient and HttpClientHandler have to be disposed between requests? What is the correct way to read a serial port using .NET framework?