VS 2015 IntelliSense: Assembly Not Referenced Error
Asked Answered
U

8

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.

Uranyl answered 23/7, 2015 at 22:23 Comment(7)
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.Fibril
@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.Uranyl
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?Liquor
@Flores: I'm on Win 7 Pro, 64. I updated everything in NuGet but I still get the red squigglies.Uranyl
@TomBaxter Did you find the solution ?Chuipek
@Chuipek - No, I have not found a solution.Uranyl
@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.Chuipek
P
49

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.

Phenol answered 26/8, 2015 at 8:26 Comment(9)
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.Bud
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.Attainture
For VS2015, just closing and restarting the IDE fixed the problem for me.Songer
This also worked for VS 2013. Thanks!!! I have been beating myself over the head with this for 3 days or more.Sanbenito
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.Sedulity
I am also getting the same issue and this solution didn't work for me. Can someone please suggest any other alternative.Bastardy
I already had a few of these, but lacked System.Core. Adding it and restarting VS did the trick.Osburn
Well, Murphy just paid me a visit. I started with other ones, nothing worked, tried this, last option, and it worked.Eri
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.Fleshy
P
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" />
Potheen answered 14/7, 2016 at 10:37 Comment(3)
Nice. For me, the seemingly random red squiggly hell was in a unit test project. I just needed this one and System.Runtime.Buckley
For vb.net it is: <Import Include="System.Core" />Roseberry
THAT did it for me. VS2019. Thanks.Excurvature
C
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.

Compatible answered 9/2, 2021 at 11:3 Comment(2)
This one worked for me on VS 2022Isolative
@RodTalingting Same for me. it fixed on VS 2022Pollypollyanna
C
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.

Chuipek answered 14/10, 2015 at 12:54 Comment(2)
I have tried almost everything I had found, but cloning from repositoty fresh copy did the job, thx for sharingCytaster
Removing the .vs folder and restarting VS2019 did the job for me. Thanks for sharing!Laevorotatory
M
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.

Mcdowell answered 23/11, 2017 at 7:6 Comment(0)
P
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!

Pitiful answered 11/9, 2018 at 9:39 Comment(0)
J
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.

Jerid answered 7/8, 2019 at 11:34 Comment(0)
M
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.

Malocclusion answered 27/7, 2016 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.