33

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.


  • 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
  • @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
  • 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
  • @Flores: I'm on Win 7 Pro, 64. I updated everything in NuGet but I still get the red squigglies. - Tom Baxter
  • @TomBaxter Did you find the solution ? - Igoris Azanovas

6 답변


36

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.


  • 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
  • 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
  • For VS2015, just closing and restarting the IDE fixed the problem for me. - Jgreenst
  • 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
  • I already had a few of these, but lacked System.Core. Adding it and restarting VS did the trick. - Lars-Erik

13

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" />


  • Nice. For me, the seemingly random red squiggly hell was in a unit test project. I just needed this one and System.Runtime. - Todd Menier
  • For vb.net it is: <Import Include="System.Core" /> - John Swaringen

1

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.


  • I have tried almost everything I had found, but cloning from repositoty fresh copy did the job, thx for sharing - eldi

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!


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.


0

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.

Linked


Related

Latest