Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predefined type System.Object is not defined or imported

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

like image 734
Hélder Gonçalves Avatar asked Oct 19 '15 13:10

Hélder Gonçalves


2 Answers

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.

like image 197
dthrasher Avatar answered Sep 29 '22 11:09

dthrasher


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?.

like image 39
Todd Sprang Avatar answered Sep 29 '22 12:09

Todd Sprang