Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 view

I'm getting 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

like image 364
mansoor Avatar asked Jun 27 '15 08:06

mansoor


People also ask

Is defined in assembly that is not referenced?

When you get this error, it means that code you are using makes a reference to a type that is in an assembly, but the assembly is not part of your project so it can't use it.

How do I fix error CS0012?

You could resolve this CS0012 by compiling with /reference:cs0012b. dll;cs0012a. dll , or in Visual Studio by using the Add Reference Dialog Box to add a reference to cs0012a. dll in addition to cs0012b.

How do I add a reference to the system core?

Right-click on the project node again and select Edit. In the editor, copy another reference line (for example, the one for "System") and paste it below the original reference inside the same ItemGroup. Change the reference name to "System. Core".


2 Answers

I am not sure if you are still having this issue or not but i was having the same issue as well.

I was able to find the solutions here

https://stackoverflow.com/questions/6496223/compilation-error-in-net-4-0-web-config-linq-not-found

<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  <add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  <add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 

I hope this helps..

like image 55
ctm1988 Avatar answered Sep 17 '22 07:09

ctm1988


This error means that Visual Studio is unable to locate the System.Web.Mvc assembly to power its intellisense for Razor views. One or both of the following may be required to fix it.

  1. Ensure the version of the .NET framework for the compilation property in the main web.config (the one in the website root) is the same as that specified in the project properties.

[root]/Web.config:

<system.web>     <compilation targetFramework="4.6" /> 

Project Properties:

Project Properties

  1. Ensure the version of the MVC assembly specified in the views web.config (the one in the views folder) is the same as the MVC assembly you are using in your project.

[views folder]/web.config:

<system.web.webPages.razor>     <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 

MVC Assembly Reference Properties:

MVC version

like image 30
Tom Bowers Avatar answered Sep 18 '22 07:09

Tom Bowers