Thursday, October 8, 2015

The type Expression<> is defined in an assembly that is not referenced.

I recently had to upgrade an older ASP.NET MVC Web Application over to MVC 5.

Since Visual Studio 2015 was recently released, I decided to use VS 2015 to perform the upgrade.

Well, after I had gone through the standard operations of upgrading all of the files in the project, I was suddenly faced with the following error message when attempting to use any Html Helpers such as @Html.LabelFor or @Html.TextBoxFor.  All of the other Html Helpers were working and intact, but these were not showing up in Visual Studio Intellisense!

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




Well, I already had a reference to System.Core in my project, so why was this error still appearing?
 
I decided to do some more testing and I discovered that NEW ASP.NET MVC projects did not face this problem!!  It was only an issue with my upgraded project!!

Fortunately, I came across this StackOverflow article which points out a resolution: http://stackoverflow.com/questions/31599087/vs-2015-intellisense-assembly-not-referenced-error

As it turns out, I needed to add some assembly references to my Web.config file as follows:

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


Once I did that, my Intellisense for these Html Helpers started working again!  Woo hoo!

4 comments:

  1. Thanks for the help! Saved me from pulling my hair out. Not sure how this was taken out of my web.config, but who cares, it is working now :)

    ReplyDelete
  2. thank you so much, you save my day

    ReplyDelete
  3. Not resolved for me :(

    ReplyDelete