asp.netvisual-studio-2015nugetsystem.web.optimization

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


I moved three .ASPX files with their associated .cs and .designer.cs files to a different folder, and changed their names. When I tried to recompile, I got the message above for 5-6 different .ASPX files, including the three that I moved. The line number in the .ASPX file was always near the top (line 10-20 or so), but on different tags each time. I also got about 250 other messages on .cs files, saying all the controls in many (perhaps all) .ASPX files do not exist.

Most articles I found about this message involved different versions of MVC, but this is not an MVC app. I did try tweaking the NuGet settings, and tried commenting out the reference in web.config to System.Web.Optimization, both without success.

I also tried excluding the offending .ASPX files from the project and re-including them. This caused the message to go away for that file, but when I excluded the last file, the same message appeared on another file, usually the next one in the project.

EDIT: Answers to several other questions address adding a missing reference, but the reference is already there in my case.


Solution

  • When you create page first time, it taking it's folder, relation each to other, and making link in this pages. Never share .aspx and .aspx.cs for different folders. If you think, that your .aspx.cs file is too big, just move to some class (for example, App_Code/MyClass), and just call that class from your .aspx.cs file. If you need correct moving, just create new .aspx page in the destination folder, and then copy code from old page to a new, and delete old page. It is best way to prevent (in your case to solve) errors