Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

c#

.net

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.

like image 378
davids Avatar asked Oct 18 '14 23:10

davids


3 Answers

I just faced this issue now:

Error

I reinstalled the optimization framework and everything worked fine:

Install-Package Microsoft.AspNet.Web.Optimization
like image 151
Shubh Avatar answered Nov 08 '22 21:11

Shubh


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

    pmc

  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>
    
like image 38
reza.cse08 Avatar answered Nov 08 '22 22:11

reza.cse08


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.

like image 9
beautifulcoder Avatar answered Nov 08 '22 20:11

beautifulcoder