I am working on an ASP.NET Core MVC, recently I got the following error and could not find web.config or system.web.mvc inside my project to fix the problem. Can anyone help me with the issue?
You must add a reference to assembly 'System.Web.Mvc, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
You need to use the correct version of the Syncfusion components designed specifically for Asp.net Core, looks like you were using the old .NET version. https://ej2.syncfusion.com/aspnetcore/documentation/chart
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.
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..
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.
Close the cshtml file
Rebuild solution
Open cshtml file
Still errors? Restart Visual studio
Still errors? Use ctm1988's answer
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
Deleting [projectName].csproj.user file from the project directory helped for me.
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.
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
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.
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>
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">
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.
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>
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
Well, I got it fixed by correcting the assembly reference in /Views/web.config, see the image:
delete bin, .vs and obj directory. after build your project on the visual studio.
Restarting Visual studio worked for me.
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.
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!
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
Close the file
Clean the solution
Build the solution
Reopen the file
Try to add
using system.Linq.Expressions;
I had this problem too.
Changing targetFramework="4.5.2" to targetFramwork="4.5"
in web.config file solved it.
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?
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.
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!
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.
In my case the solution was to move the ConnectionString inside the Web.Config. This statement should be after AppSettings section.
Installing the System.Core package with NuGet package manager works for me
In my case I checked the targetFramework of Microsoft.AspNet.Mvc in the packages.config file.
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net462" />
And I found that the targeting package was not installed.
After installing that targeting package, my issue was resolved.
I have ASP.Net MVC 2 and 3 installed. I've downloaded the complete source from github for the Rob Connery MVC Storefront here. I've opened it in VS2010, which ran the conversion wizard. When I launch it though, I get the error in the title, on the following line <li>About</li> which is line 24 in Site.Master. So I'm thinking, ah, this thing is still referencing v1 of MVC, instead of v2. So the first thing I checked is the section of the web.config, thinking that must be where the reference to version 1 of MVC is residing, however, I found the following <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />. Even in the Project References, the reference properties for System.Web.Mvc show that it is referencing v2.0 from the folder C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies. Does anyone have advice on where I can find the reference to the v1.0.0.0 of System.Web.Mvc so that I can change this to v2 in order to make the above error go away.
The most probable cause for this exception is that you are referencing some assembly in your project that implicitly depends on System.Web.Mvc 1.0. For example you might be using some DI framework which is compiled against MVC 1. So if you have ensured that in your web.config you have the correct version and that it is the correct version being referenced you might go through all other assemblies that are referenced in your project and see if they don't depend on MVC 1.0.
MVC 3 RC
I registered both System.Web.Razor and System.Web.WebPages.Razor and still have System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup not recognized in my View/web.Config
Intellisence for Razor is not working
What can be wrong with my configuration
Add the assembly "System.Web.WebPages.Razor" to the main Web.config of the application.
For some reason the "ASP.NET MVC 3 Web Application" project template included in the RC1 does not fill it.
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
It's not obvious from your question or the comments if you've done it, but in order to have full support for Razor in your system you need to install the runtime and the tooling using the following installer: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a920ccee-1397-4feb-824a-2dfefee47d54
Just putting the MVC 3 runtime binaries in your application and making changes to web.config is not enough to make Razor IntelliSense work in Visual Studio.
The problem disappeared from the time I removed Resharper
I am working with an ASP.NET MVC project which was originally started from the CodeBetter.Canvas project - and I'm trying to move to ASP.NET MVC 2. I successfully upgraded my project using Eilon's upgrade tool, moved to VS2010 (although not yet to .NET 4).
The issue I'm having currently is only occurring when using the spark view engine. Here is the relevant bit of code in my View.spark (strongly typed):
${Html.EditorFor(e => e)}
The same bit of code works just fine if I use an .aspx view:
<%= Html.EditorFor(e => e) %>
The major point here being "EditorFor" is new in ASP.NET MVC 2 and in my project I can use that helper in an ASPX view but not a Spark view.
I've tried upgrading Spark to use MVC 2 (as well as MvcContrib and Ninject), thinking maybe it was one of those that was freaking out - but so far no luck - I'm still seeing the same behavior.
Here is the full error message that is thrown from within Spark's BatchCompiler class.
Dynamic view compilation failed.
(0,0): warning CS1701: Assuming
assembly reference 'System.Web.Mvc,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
matches 'System.Web.Mvc,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35', you
may need to supply runtime policy
c:\inetpub\wwwroot[myproject]\CodeBetter.Canvas.Web\Views[MyEntity]\View.spark(9,16):
error CS1061:
'System.Web.Mvc.HtmlHelper' does not
contain a definition for 'EditorFor'
and no extension method 'EditorFor'
accepting a first argument of type
'System.Web.Mvc.HtmlHelper' could be
found (are you missing a using
directive or an assembly reference?)
Here is the Spark related code in my Global.asax:
var settings = new SparkSettings()
.AddNamespace("System")
.AddNamespace("System.Collections.Generic")
.AddNamespace("System.Web.Mvc")
.AddNamespace("System.Web.Mvc.Html")
.AddNamespace("MvcContrib.FluentHtml")
.AddNamespace("CodeBetter.Canvas")
.AddNamespace("CodeBetter.Canvas.Web")
.SetPageBaseType("ApplicationViewPage")
.SetAutomaticEncoding(true);
#if DEBUG
settings.SetDebug(true);
#endif
var viewFactory = new SparkViewFactory(settings);
ViewEngines.Engines.Add(viewFactory);
Also, I am referencing System.Web.Mvc.Html in my spark view as mentioned in another SO answer.
<use namespace="System.Web.Mvc.Html" />
The underlying issue is that a version 1.0.0 assembly is still being referenced somewhere in the project.
Using reflector to examine each assemblies dependencies, I found (if you're starting with CodeBetter.Canvas project) there are three dependent projects that need to be updated to use the 2.0.0 version of system.web.mvc.dll
Spark. Download the latest version
of spark from teamcity and use the
spark.web.mvc2.dll (which references
system.web.mvc.dll 2.0.0) Link to detailed instructions.
MVCContrib. Download the latest version
of MVCContrib (download release, download source) which references the
system.web.mvc.dll 2.0.0.
Ninject. Download the latest version of
ninject and recompile the VS solution
after updating the reference to the 2.0.0
version of system.web.mvc.dll
Now, replace these dependency's assemblies in your project and update the project references if necessary. All should be well.
I recently converted my spark project to asp.net mvc 2. I dont see in what you've written that you've switched from using Spark.Web.Mvc to Spark.Web.Mvc2.
Just to be clear, Spark.Web.Mvc2 is the project that needs to be recompiled with the new System.Web.Mvc assembly.
I had issues with intellisense until i removed all assembly and namespace references from the web.config and put them in the global.spark file and had added the pageBaseType="Spark.Web.Mvc2.SparkView" attribute to the Spark->Pages node in the web.config.
Hope any of that helps.
When you downloaded newest Spark sources, did you rebuild it using MVC 2 assemblies? Did you replace references in Spark project?
Try specifiying the System.Web.Mvc reference in the web.config instead of the Global.ascx.cs file so that you can specify the specific version:
<spark>
<compilation debug="true" defaultLanguage="CSharp">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
</spark>
This should prevent SPARK from working at all if the wrong version of the MVC assembly is being loaded from somewhere.
If the MVC 1.0 Assembly is in the GAC you can clear and reload it as follows:
(from Visual Studio command prompt)
ngen /delete System.Web.Mvc
ngen /delete System.Web.Abstractions
ngen update
Hope this helps,
Jeff French
These are the steps I took to resolve the issue with a new MVC 2 project and Spark 1.1:
Compile against MVC 2.0 - I double checked the references to make sure I was linking to MVC 2 and not MVC 1. Since this was a new project, this was not an issue.
Added System.Web.Mvc.Html - I added System.Web.Mvc.Html to the Spark configuration, to make sure that namespace was added to all views.
In Global.asax.cs Application_Start
var settings = new SparkSettings()
.SetDebug(true)
.SetAutomaticEncoding(true)
.AddAssembly("Web")
.AddNamespace("Web.Model")
.AddNamespace("System.Collections.Generic")
.AddNamespace("System.Linq")
.AddNamespace("System.Web.Mvc")
.AddNamespace("System.Web.Mvc.Html");
This can also be done in the webconfig in the Spark View Engine block.
Add the Typed Model - Make sure you type the Spark View Model. In aspx this is done with the Inherits in the page declaration, like this:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyModelType>" %>
in Spark:
<viewdata model="MyModelType" />
I tried a lot of things mentioned above but just couldn't get a dependent dll that my views used (and also referenced MVC 1.0.0.0) to use the MVC 2.0.0.0, so here is what fixed it for me...
I downloaded the Spark code and added the following line to the BatchCompiler.cs file in the Compile method:
compilerParameters.CompilerOptions = "/nowarn:1701";