Tom Baxter
Tom Baxter

Reputation: 2208

VS 2015 IntelliSense: Assembly Not Referenced Error

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.

Upvotes: 41

Views: 25647

Answers (8)

Humayoun_Kabir
Humayoun_Kabir

Reputation: 2251

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.

Upvotes: 4

Arunprasanth K V
Arunprasanth K V

Reputation: 21941

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.

Upvotes: 1

Robert McAlpine
Robert McAlpine

Reputation: 31

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!

Upvotes: 1

Edenilson Bila
Edenilson Bila

Reputation: 111

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.

Upvotes: 1

Herr Kater
Herr Kater

Reputation: 3292

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.

Upvotes: 49

Tim Peara
Tim Peara

Reputation: 131

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.

Upvotes: 0

Pedro Pedrosa
Pedro Pedrosa

Reputation: 462

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

Upvotes: 19

Igoris
Igoris

Reputation: 1650

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.

Upvotes: 2

Related Questions