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.
Related
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" />
I've encountered an odd problem: I'm trying to migrate an ASP.NET 4.0 website to an ASP.NET web application. Visual Studio's "Convert to Web Application" function actually worked quite nicely, but the only thing that's not working are the references to charts. I'm getting the error:
The type or namespace name 'Chart' does not exist in the namespace
'System.Web.UI.WebControls'
From the .designer file. The designer is automatically creating this type of code:
protected global::System.Web.UI.WebControls.Chart ClientHoursPie;
Based on research I have done, the proper 4.0 namespace to use for charts is System.Web.UI.DataVisualization.Charting. I have added the following components in the web.config (copied from the original website, which was working fine):
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
I can correct the namespaces in the designer files but each time the aspx file is saved, the designer reverts back to the old namespace.
I would love to avoid having to rebuild all of the individual pages from scratch. Is there a setting somewhere that I've missed?
Thanks in advance.
I was able to solve the problem by adding a few entries to web.config that I had missed. Anyone experiencing this problem needs to make sure you include:
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
And this (in system.webServer section):
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
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.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What is the purpose of the Assemblies node in Web.Config?
I removed all the 'add' elements in the compilation/assemblies element.
So initially in my application's root web.config file:
<compilation debug="true" 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.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
Now it looks like:
<compilation debug="true" targetFramework="4.0">
<assemblies>
</assemblies>
</compilation>
And my application still works. The project file still has all the references I removed, but this section appears to be unused during compilation (inside visual studio).
What is going on?
The references in this section of the application are used for the automatic ASP.NET compilation that is done on the fly. If you are deploying a compiled site, (no .cs or .vb files) then you are fine to remove it.
I've searched over the topics on Stackoverflow but this question hasn't been answered so far.
I have two projects in my solution: a) MVC Application b) Class Library.
The class library acts as a plugin, so it contains views. The main problem is that I have no intellisense in the view's markup for my classes contained within the class library (the same assembly as the views).
In the beginning I couldn't even write <%= Html.RenderAction... %>. I've solved that by adding a Web.config file to the class library with the following section:
<configuration>
<system.web>
<compilation debug="true">
<assemblies>
<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.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<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.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
Now it recognizes Html.RenderAction, etc in the view's markup. However I've no idea how to get access (with intellisense) to my classes contained within the same assembly as the views :(
Kind regards,
Jakub
There is a separate list of namespaces in the config where you need to include your custom namespaces. The example below demonstrates in the simplified web.config you add your namespaces. If this still does not work make sure that your project and webconfig has correct references to the other assembly.
<configuration>
<pages>
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Blog.Models"/> <!-- These are my custom namepaces -->
<add namespace="Blog.Views"/>
</namespaces>
</pages>
</configuration>
The Spark viewengine as the same issue, see their documentation. Basically they say 'make a web app project' and treat it like a class library in every other way. Worked for me in Spark, maybe it'll work in your situation as well?
Out of the box, MVC does not support multiple projects. Check my previous questions for more detail.