简体   繁体   中英

The type or namespace name 'Optimization' does not exist in the namespace 'System.Web'

I am deploying a new website as my main site and it works beautifully.

All of my applications under the root url work as well, except for one. It is a legacy system (c#.net) that is heavily used and unfortunately, I do not have access to the source code.

When I run the legacy application www.mysite.com/crm I get the following error:

Server Error in '/crm' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to 
service this request. Please review the following specific error details and modify 
your source code appropriately. 

Compiler Error Message: CS0234: The type or namespace name 'Optimization' does not 
exist in the namespace 'System.Web' (are you missing an assembly reference?)

Source Error:


Line 17:     <pages>
Line 18:       <namespaces>
Line 19:         <add namespace="System.Web.Optimization" />
Line 20:       </namespaces>
Line 21:     <controls>

Source File: e:\WebSites\newsite\Web.config    Line: 19 


Show Detailed Compiler Output:

Show Complete Compilation Source:


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446

The error is listing the web.config for the main site, which works. However, it happens only when I run the application under the main site.

This is running on Server 2008 R2 and IIS7

How do I correct this? What else can I try?

UPDATE

I don't know if it makes a difference, but the Web.Config it references in the error is for the new website, not for the legacy application. I am not sure why the main site config is a factor at all.

CLARIFICATION

I don't have access to the source code of the legacy application so I cannot adjust the properties for that application. Pasting the Optimization dll into the site didn't fix it either. It may work for other users, but not for me.

WORK AROUND

I setup the new site under another URL and redirect traffic to the root URL to the new URL and allow the legacy application to run as is until we can replace it. Very sloppy solution, but it works for now.

I just faced this issue now:

错误

I reinstalled the optimization framework and everything worked fine:

Install-Package Microsoft.AspNet.Web.Optimization

I faced same problem after create a new area in MVC5. There is auto generate web.config file. Check your web.config file under Views folder there is a line

<add namespace="System.Web.Optimization" />
  1. if you need this then install it using following command.

     Install-Package Microsoft.AspNet.Web.Optimization

    at Package Manager Console like below

    管理中心

  2. If you think no need then simply remove <add namespace="System.Web.Optimization" /> line from following section in web.config file

    <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.Web.Optimization" />--> <add namespace="AutoParts.Web" /> </namespaces>

Check the Bin folder for the legacy application. It may simply need you to drop in that DLL. The System.Web.Optimization namespace exists as of ASP.NET 4.5 so it may not even be supported. The legacy App might be older than that.

In Visual Studio .. Go to your project and see the References tree.

right click System.Web.Optimization and choose Properties

look for the path , you will find it empty if that is the case then look in your PC for the file names System.Web.Optimization.dll and copy it in the bin folder of your project and that will resolve it

I was just experiencing: "CS0234 C# The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)" and found this stackoverflow page. -- The cause for me was due to me renaming the web form (aspx page) I was working with, I also wanted to rename the public partial class behind that form. Doing so resulted in the mentioned error code. I added " using System.Web.Optimization; " to the code behind (C#), "cleaned" the solution, then "built" then solution, then "rebuilt" the solution and now the error is gone and that using statement wasn't being used, so I got rid of it. My solution no longer has that or any errors so I figured I'd share this weird story. I probably didn't need to use that " using " statement, but whatever.

从 Views/Web.config 中删除引用对我有用。

Main to Area

@Html.ActionLink("My Area Home", "Index", "Home", new { area = "MyArea" }, null)

Area to Main

@Html.ActionLink("Home", "Index", "Home", new { area = "" }, null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM