System.Web.Optimization and Microsoft.Web.Optimization won't load reference in vs 2012
Asked Answered
B

12

35

I'm working on an MVC 4 project started in Visual Studio 2010. Right now I'm working on a machine with Visual Studio 2012 as I don't have access to the machine I was originally working on. I tried all morning to find answers, but they don't seem to help my situation.

I followed How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app and installed from nuget right into my solution. Even though I have all the required reference packages downloaded and installed on my machine, System.Web.Optimization continues to remain missing. Is there anything else I can do?

Edit: When I try to build the project I receive the following errors

  • The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) - BundleConfig.cs
  • The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) - Global.asax.cs
  • The type or namespace 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?) - BundleConfig.cs

My BundleConfig.cs contains

using System.Web;
using System.Web.Optimization;

namespace BCCDC_AdminTool
{
    public class BundleConfig
    {
     // For more information on Bundling, visit http://go.microsoft.com/fwlink/?    LinkId=254725
    public static void RegisterBundles(BundleCollection bundles)
    {
           bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

           bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                    "~/Scripts/jquery-ui-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

            bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));

            bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                    "~/Content/themes/base/jquery.ui.core.css",
                    "~/Content/themes/base/jquery.ui.resizable.css",
                    "~/Content/themes/base/jquery.ui.selectable.css",
                    "~/Content/themes/base/jquery.ui.accordion.css",
                    "~/Content/themes/base/jquery.ui.autocomplete.css",
                    "~/Content/themes/base/jquery.ui.button.css",
                    "~/Content/themes/base/jquery.ui.dialog.css",
                    "~/Content/themes/base/jquery.ui.slider.css",
                    "~/Content/themes/base/jquery.ui.tabs.css",
                    "~/Content/themes/base/jquery.ui.datepicker.css",
                    "~/Content/themes/base/jquery.ui.progressbar.css",
                    "~/Content/themes/base/jquery.ui.theme.css"));
        }
    }
}
Barrelchested answered 23/4, 2013 at 21:13 Comment(2)
Are you getting some error message? If so please state more clearly if it is a compile-time or runtime error that you are getting with the exact error message. If not, please explain more clearly the precise problem you are currently encountering.Ious
I've added more information...I'm not sure if there is anything else I can provide.Barrelchested
S
12

This is a long shot but here it goes anyway, right click on the project --> Property Pages and make sure System.Web.Optimization entry exists. If not, copy the System.Web.Optimization.dll to your bin folder or import it as a reference.

Edit: mvc projects don't have the "Property pages" menu option.

One other thing you can try is create a new mvc4 basic project, go to the bin folder of the solution and copy the System.Web.Optimization.dll to the bin folder of your other project that is giving you the error. If you can't find the dll then try updating the nuget packages.

Stopping answered 23/4, 2013 at 21:52 Comment(2)
This is where my lack of experience shines. I don't see anywhere that shows that kind of information on the Property Pages of my project. I also actually can't seem to find the System.Web.Optimization.dll anywhere on my PC... That does seem like a good solution to me though.Barrelchested
Sorry, my bad, mvc projects don't have "Property pages" option.Stopping
C
79

I had the same problem with a VS2010 project I opened in VS2012. The Microsoft.AspNet.Web.Optimization package was missing so I just needed to download it using Nuget Package Manager.

You can run in the console: Install-Package Microsoft.AspNet.Web.Optimization

Cruse answered 22/7, 2013 at 13:1 Comment(1)
Well, I think he tried that. Actually in his own words "I followed How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app and installed from nuget right into my solution. Even though I have all the required reference packages downloaded and installed on my machine, System.Web.Optimization continues to remain missing. Is there anything else I can do?"Stopping
N
59

I know it's confusing, but you will need to Install-Package Microsoft.AspNet.Web.Optimization

Nogood answered 1/7, 2013 at 9:8 Comment(0)
S
14

Try going to the web.config in the Views folder and removing the following line:

        <add namespace="System.Web.Optimization" />

That fixed it for me.

Smallsword answered 19/2, 2014 at 16:49 Comment(1)
This worked for me. My situation was that I added MVC 4 to an older Web Forms .NET 4.0 project. I added the Microsoft.AspNet.Web.Optimization nuget package but for some reason still got this error when the site was deployed to a live server. Removing this from the Views Web.config resolved the issue for me.Camp
S
12

This is a long shot but here it goes anyway, right click on the project --> Property Pages and make sure System.Web.Optimization entry exists. If not, copy the System.Web.Optimization.dll to your bin folder or import it as a reference.

Edit: mvc projects don't have the "Property pages" menu option.

One other thing you can try is create a new mvc4 basic project, go to the bin folder of the solution and copy the System.Web.Optimization.dll to the bin folder of your other project that is giving you the error. If you can't find the dll then try updating the nuget packages.

Stopping answered 23/4, 2013 at 21:52 Comment(2)
This is where my lack of experience shines. I don't see anywhere that shows that kind of information on the Property Pages of my project. I also actually can't seem to find the System.Web.Optimization.dll anywhere on my PC... That does seem like a good solution to me though.Barrelchested
Sorry, my bad, mvc projects don't have "Property pages" option.Stopping
L
8

I battled this for an hour and none of the above suggestions worked. In the end only the following worked (for some obtuse reason) :

  1. ctrl-q -> type "package manager console"
  2. Uninstall-Package Microsoft.AspNet.Web.Optimization <problem project name>
  3. Install-Package Microsoft.AspNet.Web.Optimization <problem project name>

WARNING/HEADS-UP

  • the above will install the latest version of Microsoft.AspNet.Web.Optimization. If you want a particular version (say v1.1.1), use Install-Package Microsoft.AspNet.Web.Optimization <problem project name> -Version 1.1.1
  • don't forget the <problem project name> parameter or nuget will operate at the Solution-level, possibly trampling sibling projects.
  • Note that omitting the project name is an of itself really handy for doing Solution-level version updates or package installs.
Libau answered 29/10, 2015 at 18:39 Comment(1)
Update-Package -reinstall Microsoft.AspNet.Web.Optimization - it's a two-fer (not sure if nay differences, but it worked for me)Manus
N
6

Go to tools >> Library Package Manager >> Manage Nuget Packages >> install Microsoft ASP.NET web optimisation framework

Nitza answered 24/4, 2014 at 10:26 Comment(0)
P
3

Uninstalling, and reinstalling the Microsoft.AspNet.Web.Optimization package solved it for me.

Preeminence answered 22/8, 2014 at 10:24 Comment(0)
F
1

I fixed this issue by setting the reference to the assembly System.Web.Optimization.dll to copy local to true.

Flannery answered 28/1, 2014 at 20:15 Comment(0)
D
1

Reinstalling system.web.optimizaiton using Nuget package manager solved this issue for me..

Daiquiri answered 23/2, 2016 at 1:32 Comment(0)
C
0

What worked for me in a specific scenario (I downloaded a MVC project from source control and received that error), was to open a new MVC project on the same solution. Afterwards I could delete the new project I've created and it still works (on VS2012).

Collimore answered 21/10, 2014 at 15:55 Comment(0)
S
0

Simple Solution. Open Visual Studio in administrator mode. It will resolve your error.

Sumba answered 29/4, 2020 at 18:49 Comment(0)
E
-2

I know there are many answers to this issue, but give this a try- open the project in visual studio as an Administrator.It did solve in my case.

Ehrenberg answered 16/4, 2015 at 16:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.