Predefined type System.Object is not defined or imported
Asked Answered
V

5

14

I'm having this weird error only in .cshtml files in VS 2015. The error doesn't show up when I open the project with VS 2013.

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

here are my 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" />

What might be the cause of this?

Please refer to this question that I created as well. It's the same issue: The type or namespace name 'System' could not be found

Vocalism answered 19/10, 2015 at 13:1 Comment(3)
If you create a new project in VS 2013 and try opening it in VS 2015 do you see the same error?Nunci
I had a lot of errors (~4000) similar to the ones above. After i added <Reference Include="mscorlib" /> in csproj, all the errors disappearedEbonize
I just had this issue in VS 2019 cshtml page. I would get highlighted code with this error but code itself would run perfectly fine. Closing and opening VS solved this problem.Know
A
5

I had a lot of CSHTML Intellisense issues with MVC 4 in VS 2015 and opted just to upgrade to MVC 5. However, MVC 4 should still work, just not perfectly, according to: Does Visual Studio 2015 support older versions of MVC?.

Ambala answered 26/10, 2015 at 14:20 Comment(0)
I
11

This is a problem in both VS 2013 and VS 2015. Build output must be set to the default build path in order for Razor intellisense to work in .cshtml files. See this excellent article reproducing the issue and discussing alternatives. http://www.dennisonpro.info/managing-intellisense-in-razor-views-with-mvc-5-using-custom-builds-in-visual-studio-2013/

So the build path must be set to bin\ for MVC projects. If you need your output to go somewehere else, you must create a post-build step that copies the files from bin\ to another location.

Illuse answered 24/7, 2016 at 16:9 Comment(1)
Thanks, that resolved my issue. I had a website that was going to need to be merged with another so I had redirected the bin path.Bantam
A
5

I had a lot of CSHTML Intellisense issues with MVC 4 in VS 2015 and opted just to upgrade to MVC 5. However, MVC 4 should still work, just not perfectly, according to: Does Visual Studio 2015 support older versions of MVC?.

Ambala answered 26/10, 2015 at 14:20 Comment(0)
S
2

Deleting bin and obj folders in all projects of that solution worked for me.

Seems like those were having old files generated by some older version of visual studio, which are not compatible with new version of visual studio.

Shipowner answered 31/5, 2018 at 15:11 Comment(0)
V
0

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. After I changed the build root and reloaded the project, the errors were gone and intellisense appeared.

Vocalism answered 28/10, 2015 at 16:54 Comment(0)
I
-5

Add the reference to the System assembly in the project references:

right click on references -> add reference -> assemblies -> Framework -> System

Impala answered 19/10, 2015 at 13:50 Comment(3)
And System.Object isn't even in the System assembly - it's in mscorlib.Protraction
Sorry, I'm not following you. Who mentioned System.Object?Impala
The title of the question.Ineffective

© 2022 - 2024 — McMap. All rights reserved.