The type or namespace name 'System' could not be found
Solution 1
I attempted to re-create your issue and came up with a similar error when the solution was created in visual studio 2013 and then tried building it in in vs 2015.
I was able to get a successful build once I reinstalled NuGet Package Manager (and closed, then reopened VS 2015).
References / Credit
There are several SO questions relating to build issues via with earlier version of NPM for VS 2015 (i.e. I'm just passing along what I've tried and worked out). Recurring resolution is usually update / reinstall NPM or change execution policy in power shell. I tend to like the update + restart approach to avoid tinkering with the black boxes in windows. one source: https://stackoverflow.com/a/32251092/1158842 There may also be an issue of MSBuild Integrated solutions, in which case migrating away from the NuGet resources in the solution could do the trick.
Source: https://stackoverflow.com/a/31811461/1158842
Solution 2
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.
Solution 3
Cleaning solution worked for me.
I would also advise to close and relaunch Visual Studio once doing so.
Solution 4
Follow these steps :
- right click on Solution > Restore NuGet packages
- right click on Solution > Clean Solution
- right click on Solution > Build Solution
- Close Visual Studio and re-open.
- Rebuild solution. If these steps don't initially resolve your issue try repeating the steps a second time.
Thats All.
Solution 5
Unload project -> Reload project normally fixes this weird, Nuget related, error to me.
Related videos on Youtube
Hélder Gonçalves
Software Engineer with interest in .Net, C# and PL/SQL.
Updated on July 08, 2022Comments
-
Hélder Gonçalves almost 2 years
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:
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.
-
hubson bropa over 8 yearsnothing odd there. do you have a using clause for it n your views? if not you may not have to, i bet you can add it implicitly via the Views web.config...see this question stackoverflow.com/questions/12547641/…
-
Hélder Gonçalves over 8 yearsthe issue is not only with the using clauses.. it's also when I try do to @Html, please see the updated question
-
Backs over 8 yearswhat VS version do you use? what MVC version of your project?
-
hubson bropa over 8 yearsdid you have this project in a previous version of visual studio? if so it may be a nuget package restore issue....stackoverflow.com/questions/27895504/…
-
Hélder Gonçalves over 8 years@hubsonbropa When I open the project in VS 2013 it works fine. This only happens in VS 2015
-
RBT over 2 years
-
StuartLC over 2 yearsYet another reason why VS can't find any of the System is because it can't install a framework or core dependency dll is because the nuget package sources have been deleted or corrupted. Make sure that at least
https://api.nuget.org/v3/index.json
is added
-
-
monty over 6 yearsThis worked for one of my solutions that had this problem; but another required VS to be relaunched after cleaning.
-
WasiF over 6 yearsclean solution, restart visual studio and build solution... this worked, Thanks
-
pollaris over 6 yearsYou need to leave your XAML and CS windows open when you close VS.
-
CularBytes over 6 yearsHahaha when you spent half an hour trying to install .NET standard while it seems you already have everything. Thanks
-
Andrew about 5 yearsHow do you "clean" the solution? Right click > Clean
-
Nil about 5 yearsSolution Explorer -> Right click on your project -> Clean
-
rsmith over 4 yearsThe issue for me seemed to be that the framework was already downgraded (4.5) compared to my other projects (4.5.1). Upgrading the framework to 4.5.1 & closing VS, re-opening & then building worked. Upvoted since this was the only one that mentioned the framework. Thanks!
-
RayLoveless about 4 yearsI needed to run step 4 before step 3.
-
kcho0 over 3 yearsAgree, just restarted VS (A.K.A. "IT Weapon of Choice") worked for me too.
-
SendETHToThisAddress over 3 yearsIt probably resolved your issue because VS 2019 has more built-in mechanisms for automatically resolving issues.
-
SendETHToThisAddress over 3 yearsI recommend adding this to your post: "5. Rebuild solution. If these steps don't initially resolve your issue try repeating the steps a second time."
-
Marcelo Luz about 3 yearsFor me, restarting Visual Studio (after rebuilding the solution) solved the problem.
-
0xcrypto over 2 yearsInstead of cleaning the solution, you should rebuild the solution. Clean only if rebuilding the solution didn't work.
-
Roro about 2 yearsCleaning and rebuilding worked for me.
-
Suncat2000 almost 2 yearsI second this post. Sometimes cleaning the solution is not enough and rebuilding the solution will repair the references.