wrong module specified in web.config - asp.net

Visual Studio 2010
I have System.Web.MVC 2 and System.Web.Routing 4 referenced in my project.
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
I am getting a following error when specifying a module:
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,System.Web.Routing, Version=4.0.0.0,Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Error: Wrong module specified. System.Web, version 4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Note: i am upgrading Kentico CMS to new version and they are now utilizing routing also. The upgrade document wants to add a module with version 3.5.0.0. Since i have version 4.0 referenced, i cant do 3.5.

Try
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Related

What does the web.config compilation/assemblies element do?

I had a problem where, working on a new MVC project, as soon as I added Html.Partial("Name") to my _Layout.cshtml page, ASP.NET would throw this exception on page load:
error CS0012: The type 'System.Object' is not in a referenced assembly is defined. Add a reference to the Assembly "System.Runtime, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" added.
The fix is to add this to the web.config, compilation element:
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
I'd love to know why this fixes the issue.
What's odd is that the new MVC app I'm using has a load of WebForms ASPX pages that work a treat. I've copied a ton of legacy WebForms stuff into this new MVC project, acres of code, and everything works, and without the Html.Partial call, even my MVC view renders.
So what on Earth is going on? What does this config do and why aren't the normal project references and target framework settings enough?
This is caused by a disconnect and limitation between the build time and the runtime environments of an ASP.NET/MVC project. Most code in a Web project is compiled at build time (ie F5) with exception to views (both Razor and inline ASPX code) which are built dynamically at runtime (ie within IIS).
For the most part, we attempt to make these two environments exactly the same and you will not typically notice any difference. Unfortunately. you've run into one of those cases where there is a difference and you've needed to manually add a reference to make the runtime mimic build-time.
What's happening, is that you likely have a dependency on a portable library (at a guess, Microsoft.Net.Http). Portable Libraries are a little different to normal libraries, and we need extra references to make the compiler happy. At build-time we detect a dependency on a portable library and automatically add all the references to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades. Unfortunately, the runtime doesn't do this and you need to manually add these references until we fix this in a future release.
For future reference, you can just grab the following section and paste this directly into Web.Config (this represents the snapshot for 4.5):
<compilation>
<assemblies>
<add assembly="System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Collections.Concurrent, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ComponentModel.Annotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ComponentModel.EventBasedAsync, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Diagnostics.Contracts, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Diagnostics.Debug, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Diagnostics.Tools, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Diagnostics.Tracing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Dynamic.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Linq.Parallel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Linq.Queryable, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Net.NetworkInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Net.Requests, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Reflection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Reflection.Emit, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Reflection.Emit.ILGeneration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Reflection.Emit.Lightweight, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Reflection.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Reflection.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.InteropServices.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.Serialization.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.Serialization.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Runtime.Serialization.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Security.Principal, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ServiceModel.Duplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ServiceModel.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ServiceModel.NetTcp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ServiceModel.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.ServiceModel.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Text.Encoding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Text.Encoding.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Text.RegularExpressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Threading, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Threading.Tasks.Parallel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Xml.ReaderWriter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Xml.XDocument, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Xml.XmlSerializer, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
Encountered the exact same error after switching to VS 2017 & C# 7.1 and adding references to System.ValueTuple into my .NET 4.6 ASP.NET project
Problem solved by activating Roslyn in ASP.NET projects without fiddling with references in web.config
Added benefit of this is you can use new C# features in aspx pages and MVC views
I ran into this when I cleared assemblies due to being in an IIS application where the parent was referencing things I didn't want.
<system.web>
<compilation>
<assemblies>
<clear />
</assemblies>
</compilation>
</system.web>
Should have been obvious in hindsight, but the error didn't really seem linked to the cause.
I ran into a similar situation.I had an MVC project with Unity. Project was targeting .Net version 4.5.1 but my build machine was missing the 4.5.1 folder in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework folder.
So what solved my problem was copying v4.5.1 folder from my dev machine to the build machine.
You can find the link to the original answer here
Visual Studio 2017 MVC.RAZOR fixed by adding this to web app web.config section: here is a snippet of my Web.Config just after system.web node:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.1">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5.1" />

ASP.NET website too slow while debug=false

I have a performance issue with my ASP.NET MVC3 application,
I noticed that the pages are retrieved very slowly (~30sec per request) when a put debug="false" in the web.config file.
If I keep debug="true" the loading & navigation are not slow at all.
It sounds very strange and I didn't find a similar problem in the web.
here is the compilation section of the web.config :
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
I'm using IIS Express 7.0 on my local machine and IIS 6 on the production server (same issue)

MVC 2/ASP.NET 4.0 App not working

I have picked up a project that is currently broken and I'm trying to fix it.
The application was last working correctly as a .NET 3.5 Web Forms application with some features implemented in MVC 2.0.
The application has become broken when it was upgraded to .NET 4.0 and is running on IIS 7. The Web Forms features work fine, but the MVC 2.0 parts no longer work. Browsing to an MVC URL fails with a 404 error. It seems as if MVC does not kick in when the URL is browsed.
I've put extracts from the web.config below.
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<system.webServer>
<modules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
</handlers>
</system.webServer>
It works on the development PC (Windows 7). Why is MVC not working when deployed to IIS 7 (Win 2k8)?
The modules element requires the runAllManagedModulesForAllRequests to be set as described in this answer.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
</handlers>
</system.webServer>

ASP.Net web forms compilation says Entity Framework reference missing

I have a website using ASP.Net Webforms and Entity Framework and during compilation VS2010 tells me the following error:
error CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The problem is that the reference is properly configured in web.config
The properties page of the project says that the Framework version used in the project is v3.5, which is correct.
Any help will be appreciated.
This is the assemblies section in my web.config
<assemblies>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>.
can you show your web.config references? My guess is that either the version # is off, or that perhaps the EF assmebly is not installed in the GAC.
Check that the exact version you want is referenced in web.config
If the assembly is in your bin directory, right click on it in Windows Explorer and choose 'Properties' and find the version. Make sure it matches web.config.
If you are relying on the GAC, open c:\windows\assembly in Windows Explorer to see if that exact version of the EF assembly is there
The only time I get that is when the DLL is missing from a project, and it may not just be the root project. If you have another project that uses the EntityObject class, and its missing there, you'll get the error.

Compilation error in .NET 4.0 web.config - Linq not found

I can compile and test my .NET 4.0 web application just fine within Visual Studio 2010. If, however I point my local IIS to the folder containing the application, I get the following error:
Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
Source Error:
Line 388: <add namespace="System.ComponentModel.DataAnnotations" />
Line 389: <add namespace="System.Configuration" />
Line 390: <add namespace="System.Linq" />
Line 391: <add namespace="System.Text" />
Line 392: <add namespace="System.Text.RegularExpressions" />
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config Line: 390
How is it that the web.config from the framework won't compile for me?
I have found similar problems on the web and most just say 'add this reference...', but it can't be the right thing to edit the default web.config -- can it?
This worked for me. Have this assemblies in the web.config file
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
I think you need to add the assemblies below in your web.config -
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
You will get System.Linq in core assembly
If you have a website, asp.net needs proper references to be able to compile it. A web application would not need that.
There are some assemblies referenced in the machine.config, some might be missing depending on your code, you can add them to machine.config or the root web.config.

Resources