The type 'Expression<>' is defined in an assembly that is not referenced
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.
- 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:
- 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:
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.
- Go to Project-> NuGet Package Manager.
- Search for MVC; it's going to be the first result.
- 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.
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..
- Close the cshtml file
- Rebuild solution
- Open cshtml file
- Still errors? Restart Visual studio
- Still errors? Use ctm1988's answer