41

I just switched to VS 2015. I have an older MVC 5 app that runs against 4.52. In VS 2013 it's perfectly fine.

In VS 2015 I'm getting red squigglies under my @Html.TextBoxFor() with an error indicating:

The type 'Expression<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

The project builds and runs just fine -- but I am concerned about the IntelliSense error that never happened in VS 2013. Okay, so I try to add the reference to System.Core as recommended in the error above and then I get this error:

A reference to 'System.Core' could not be added. This component is already automatically referenced by the build system.

Again, this is fine in VS 2013.

Tom Baxter
  • 2,110
  • 2
  • 19
  • 38
  • This can happen if you are using MVC 4, since MVC 4 tooling is not included with Visual Studio 2015. Only MVC 5 and MVC 6 tooling is included. Can you confirm you are using MVC 5 by opening packages.config and scrolling to the entry for Microsoft.AspNet.Mvc. If the version listed starts with "5", this means you are using MVC 5. – Mohit Srivastava Jul 24 '15 at 23:41
  • @Mohit - I am using version 5.2.2 of Microsoft.AspNet.Mvc yet I am using version 3.2.2 of Microsoft.Asp.Net.Razor. – Tom Baxter Jul 25 '15 at 16:37
  • I have the exact same problem, but only on my Windows 7 machine, on Windows 10 there is no problem. Which version of windows are you running? – Flores Jul 30 '15 at 13:09
  • @Flores: I'm on Win 7 Pro, 64. I updated everything in NuGet but I still get the red squigglies. – Tom Baxter Aug 07 '15 at 22:33
  • @TomBaxter Did you find the solution ? – Igoris Azanovas Oct 14 '15 at 11:34
  • @Igoris - No, I have not found a solution. – Tom Baxter Oct 16 '15 at 02:57
  • @TomBaxter I deleted solution folder, then downloaded latest sources, and everything seems to be ok. All other solutions like changing web.config, removing user data, MEF cache clearing did not do a thing. But getting new solution to disk did the thing. – Igoris Azanovas Oct 16 '15 at 07:49

8 Answers8

48

I had the same issue, but in the mean time I've found the answer:

I had to add the following references to my web.config (add inside the opening system.web tag):

<compilation debug="true" targetFramework="4.5">
    <assemblies>
                <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
                <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
                <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
                <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
                <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
                <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            </assemblies>
        </compilation>

I also changed the target framework from 4.5.1 to 4.5.

p.s Close and reopen Visual Studio after changing it.

Reza
  • 18,865
  • 13
  • 88
  • 163
Herr Kater
  • 3,242
  • 2
  • 22
  • 33
  • 2
    After following this, if you still do not see anything change. Just reset the studio. I don't know why but it works for me. – nguyenhoai890 Jan 13 '16 at 15:55
  • This worked for me, I had the same problem as the OP. It doesn't matter if this is in the View folder's Web.config, it needs to be in the application's Web.config, just FYI. Resetting VS2015 didn't do anything for me. – Josh Mar 05 '16 at 21:26
  • 3
    For VS2015, just closing and restarting the IDE fixed the problem for me. – Jgreenst May 19 '16 at 16:52
  • This also worked for VS 2013. Thanks!!! I have been beating myself over the head with this for 3 days or more. – David P Sep 07 '16 at 15:41
  • 2
    I got rid of the error by adding only the System.Core assembly to the web.config file in the Views folder, then doing a Clean Solution, then closing and reopening Visual Studio. – Michael12345 Sep 25 '16 at 20:47
  • I am also getting the same issue and this solution didn't work for me. Can someone please suggest any other alternative. – Karan May 04 '17 at 07:48
  • 1
    I already had a few of these, but lacked System.Core. Adding it and restarting VS did the trick. – Lars-Erik Aug 01 '17 at 12:01
  • Well, Murphy just paid me a visit. I started with other ones, nothing worked, tried this, last option, and it worked. – dbinott Aug 15 '18 at 05:32
  • For me, this mess started when we upgraded from System.Web.Mvc 5.2.3 to v5.2.6. After two reinstallations and pretty much every solution across SO and other sites, this is the one that works. Notably, it was the addition of the correctly versioned System.Web.Mvc of 5.2.6 to the main web.config that solved it. Prior to adding it, the only two assemblies in the section were System.Runtime and System.Globalization. This on VS 2017 15.6.7, and for some reason, only affecting some members of the team. – Jeff Woods Sep 11 '18 at 13:51
19

I have tried most of these, what eventually worked for me was unloading the project, edit the csproj file, and add the following:

<Reference Include="System.Core" />
Pedro Pedrosa
  • 462
  • 4
  • 13
4

In my case (VS 2019) I have to add this in .csproj file after unload the project

<Reference Include="System.Core" />

need to change in ProjectGuid tag like below:

<ProjectGuid>{6C651A5E-8DDA-4680-804E-F9596743CBE8}</ProjectGuid>

then reload the project and add this tag to web.config like below:

<compilation debug="true" ...>
<assemblies>
            <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            ...
        </assemblies>
    </compilation>

and after that just rebuild the project and all the error is gone in my case.

Humayoun_Kabir
  • 2,003
  • 1
  • 17
  • 13
2

Only deleting solution and getting solution from source control solved this for me, removing .vs folder and starting VS2015 as "devenv.exe /resetuserdata" did not solve my problem, event removing MEF component cache did not solve as per Razor intellisense not working in VS 2015 answers.

Community
  • 1
  • 1
Igoris Azanovas
  • 1,640
  • 1
  • 22
  • 37
  • I have tried almost everything I had found, but cloning from repositoty fresh copy did the job, thx for sharing – eldi May 18 '16 at 20:51
  • Removing the .vs folder and restarting VS2019 did the job for me. Thanks for sharing! – Tillito Nov 22 '19 at 21:44
1

In my case, it worked after changing the tag <ProjectGuid> in .csproj file to <ProjectGuid>{6C651A5E-8DDA-4680-804E-F9596743CBE8}</ProjectGuid> and reopening the solution. All of the solutions posted above did not work for me.

adiga
  • 34,372
  • 9
  • 61
  • 83
1

From updating from 4.5.2 to 4.6.1 I got these exact errors in my views. Building and running the solution worked absolutely fine. After trying all the solutions already posted here, (and also checking intellisense for working, clearing caches, removing bin and obj folders, loading and reloading the project) nothing worked whatsoever (system.core was already being built correctly and adding in those references to the Web.config did nothing). I did my own digging and eventually found that in the project where the error was occurring the Web.config file contained two compilation debug target frameworks and a different httpRuntime target framework. Like so:

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.6.1" />
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.1" />
    ...

The solution was to resolve this by removing the extra compilation debug target framework and to ensure all target frameworks were the one I wanted (4.6.1)

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
    ...

Double check this if nothing else works. Hope that helps someone!

1

If anybody is facing this issue with

VS 2017 , .net framework version 4.8 and MVC version 5.2.7

Then check your Microsoft.CodeDom.Providers.DotNetCompilerPlatform version, If you have 2.0.1 version installed then downgrade it to 2.0.0 

enter image description here

Then check the MVC version, you have to downgrade it to 5.2.4

enter image description here

Then downgrade Microsoft.AspNet.WebPages 3.2.7 to   Microsoft.AspNet.WebPages 3.2.4 
and Microsoft.AspNet.Razor 3.2.7 to Microsoft.AspNet.Razor 3.2.4 

try to run the application now, it will work.

Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71
0

I tried these and other solutions on other Stack Overflow threads. None worked.

What worked was repairing the installation of Visual Studio which is found in the System Settings, Apps & features sub-menu (click on VS and choose "Repair"). It took a couple of hours, but then the problem disappeared.

Tim Peara
  • 131
  • 1
  • 6