asp.net-mvcasp.net-mvc-5.1

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


In ASP.NET MVC 4.5.2 Framework, after typing @Html.LabelFor() or @Html.EditorFor() in a view, I'm getting this error:

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

I have added assembly reference System.Core.dll, Version 4.0.0.0, Runtime Version v4.0.30319, and also I did in web.config.


Solution

  • I have run in the same issue as you, albeit much later. The issue was that I was not able to access Razor views (.cshtml) as I was getting an error stating that I had a missing assembly reference, namely System.Web.Mvc, even though it was in the project references. After investigation, I have noticed that the installed NuGet version was 5.2.3, while the project required 5.2.0. The solution is to downgrade the MVC version.

    1. Go to Project-> NuGet Package Manager.
    2. Search for MVC; it's going to be the first result.
    3. Next is to select downgrade from the drop-down in the details of the NuGet package and submit.

    Confirm all the dialogs and you are ready to go.