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

asp.net Mvcasp.net Mvc-5.1

asp.net Mvc Problem Overview


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.

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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

Solution 2 - asp.net Mvc

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

Solution 3 - asp.net Mvc

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.

Solution 4 - asp.net Mvc

  • Close the cshtml file
  • Rebuild solution
  • Open cshtml file
  • Still errors? Restart Visual studio
  • Still errors? Use ctm1988's answer

Solution 5 - asp.net Mvc

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

https://stackoverflow.com/a/38371981/2335660

Solution 6 - asp.net Mvc

Deleting [projectName].csproj.user file from the project directory helped for me.

Solution 7 - asp.net Mvc

I just had the same exact issue and none of the solutions fixed the problem. I had to add this into my web.config within System.Web

<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />

I had removed it when changing some of the config around.

Solution 8 - asp.net Mvc

I've had the same problem with missing assembly and it happened that VS2017 build has not copied it properly into the Bin folder. These steps helped me:

>

  • Navigate to the web project's References node
  • Find the reference to System.Core
  • Open the VS Properties Window
  • In the properties window, change Copy Local: False to True

from this comment: CS0012: The type '#####Any type#####' is defined in an assembly that is not referenced

Solution 9 - asp.net Mvc

In my case this message was shown only when Resharper was turned on. I have cleared Resharper cache, restarted VS, turned Resharper off and turned it on again. The message has dissapeared.

Solution 10 - asp.net Mvc

I did ALL of the above and in the end found that what solves it for me (on a .net framework 4.7.1 site with MVC 5.2.4) was adding this into the root web.config within <compilation> -

<assemblies>
  <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>

Solution 11 - asp.net Mvc

In Web.config I needed to change:

  <system.web>
    <compilation debug="true" targetFramework="4.7">

to

  <system.web>
    <httpRuntime targetFramework="4.7" />
    <compilation debug="true" targetFramework="4.7">

Solution 12 - asp.net Mvc

Check that the cshtml file Build Action is set to 'Content'.

I use ReSharper and have noticed that for some reason the file that is generated defaults to 'None' when invoking the template.

Solution 13 - asp.net Mvc

Add the following to Web.config (in root). I tried absolutely everything of earlier suggestions and nothing worked until I found the below. Hope it will save time for someone else.

I use targetFramework="4.6.1", but change it to the version you use if different.

<system.web>
   <compilation debug="true" targetFramework="4.6.1" />
   <httpRuntime targetFramework="4.6.1" />
</system.web>

Solution 14 - asp.net Mvc

Add the System.Core.dll file to the bin folder manually. Restart VS and build project. Solved for me

Had design errors in all views on @Html helpers and on my Kendo grids.

Adding System.Core assembly in Web.config did nothing, nor did downgrading the MVC version. And error when trying to add reference to System.Core manually:

> A reference to 'System.Core' could not be added. This component is > already automatically referenced by the build system.

Make sure to check that TargetFramework in project properties matches the one in project web.config.

Screenshot of bin folder

Solution 15 - asp.net Mvc

Well, I got it fixed by correcting the assembly reference in /Views/web.config, see the image:

enter image description here

Solution 16 - asp.net Mvc

delete bin, .vs and obj directory. after build your project on the visual studio.

Solution 17 - asp.net Mvc

Restarting Visual studio worked for me.

Solution 18 - asp.net Mvc

For me, there was an option under the project menu to "Enable C# 6.0/VB 14". Selecting this option did the trick. Previously I tried modifying the web.config, restarting Visual Studio, etc as was suggested in this post.

Solution 19 - asp.net Mvc

I faced the same problem. Basically the problem is using different version of System.Web.Mvc. So the best thing you should the open Tools > Nuget Package Manager > Manage Nuget Packages for Solution. You can probably see System.Web.Mvc on the Cosolidate tab. Upgrade or downgrade would be the best option. If you use the latest .Net framework, which is currently .Net 4.6.1, you should upgrade the all System.Web.Mvc versions to 5.2.4.0. Good luck!

Solution 20 - asp.net Mvc

This happened with one of my views - all the others were fine. I did the following:

  • Create a new view
  • Copy and paste the contents from the old view to the new one
  • Deleted the old one
  • Renamed the new one to the old one

Solution 21 - asp.net Mvc

In my case the solution was to move the ConnectionString inside the Web.Config. This statement should be after AppSettings section.

Solution 22 - asp.net Mvc

I had this problem too. Changing targetFramework="4.5.2" to targetFramwork="4.5" in web.config file solved it.

Solution 23 - asp.net Mvc

  • Close the file
  • Clean the solution
  • Build the solution
  • Reopen the file

Solution 24 - asp.net Mvc

Try to add

using system.Linq.Expressions;

Solution 25 - asp.net Mvc

If you get this in only one or two CSHTML files... it's a corrupt file.

I've had this happen with a corrupt file that has some hidden unicode characters. Try copying all the text of the document to a fresh notepad instance. Clear the contents of the original file and save... if the file length is > 0, there's something awry.

Delete the file and save your notepad instance over the old version. All the errors went away for me.

I've had this happen a couple of times in my solution. Not sure what's causing it, but I suspect it's Resharper screwing up when it starts to swallow huge chunks of memory into the abyss.

Am I the only one who has a love / hate relationship with Resharper?

Solution 26 - asp.net Mvc

This can be caused if you have multiple projects in your solution that don't all target the same version of the .NET Framework. For example, if your web app project targets .NET 4.5 and you have an assembly reference to another project in the solution that targets .NET 4.5.2. To fix this you need to change your projects to all target the same version of the .NET Framework.

Solution 27 - asp.net Mvc

If none of the answers work use this one. I faced the same issue! Actually configuration.cs file in migrations folder was missing/deleted. I did delete migrations folder and also did delete migrations table from database. Next in Package Manager Console (PM) used following commands:

Enable-Migrations -Force
Add-Migration Initial
update-database

This process recreated the configuration.cs file and everything worked perfectly!

Solution 28 - asp.net Mvc

Check your project properties to get the Target framework. I resolved this issue in my project by matching for my target framework .NET framework 4.6.1 MVC 5.2.3 was the apt solution. I got that MVC version from NuGet.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmansoorView Question on Stackoverflow
Solution 1 - asp.net Mvcctm1988View Answer on Stackoverflow
Solution 2 - asp.net MvcTom BowersView Answer on Stackoverflow
Solution 3 - asp.net MvcPrashant2008View Answer on Stackoverflow
Solution 4 - asp.net MvcCularBytesView Answer on Stackoverflow
Solution 5 - asp.net Mvcleyla azariView Answer on Stackoverflow
Solution 6 - asp.net MvcRobo BurnedView Answer on Stackoverflow
Solution 7 - asp.net MvcjsanmanView Answer on Stackoverflow
Solution 8 - asp.net MvcAngel DinevView Answer on Stackoverflow
Solution 9 - asp.net MvcNeshtaView Answer on Stackoverflow
Solution 10 - asp.net MvcAndyView Answer on Stackoverflow
Solution 11 - asp.net MvcjuFoView Answer on Stackoverflow
Solution 12 - asp.net MvcKevin R.View Answer on Stackoverflow
Solution 13 - asp.net MvcNjål EideView Answer on Stackoverflow
Solution 14 - asp.net MvcpkucasView Answer on Stackoverflow
Solution 15 - asp.net MvcAltafView Answer on Stackoverflow
Solution 16 - asp.net MvcNisanurView Answer on Stackoverflow
Solution 17 - asp.net MvcMangesh KadamView Answer on Stackoverflow
Solution 18 - asp.net MvcAggromonsterView Answer on Stackoverflow
Solution 19 - asp.net MvcMehmet Taha MeralView Answer on Stackoverflow
Solution 20 - asp.net MvcLiamView Answer on Stackoverflow
Solution 21 - asp.net MvcRogerio PicilliView Answer on Stackoverflow
Solution 22 - asp.net Mvcmaryam bView Answer on Stackoverflow
Solution 23 - asp.net MvcJephView Answer on Stackoverflow
Solution 24 - asp.net Mvcuser1223339View Answer on Stackoverflow
Solution 25 - asp.net Mvcuser910531View Answer on Stackoverflow
Solution 26 - asp.net MvcChris PietschmannView Answer on Stackoverflow
Solution 27 - asp.net MvcShah AadilView Answer on Stackoverflow
Solution 28 - asp.net MvcSukesh MullasseryView Answer on Stackoverflow