3

I'm using latest MVC4-RC (.net 4.0) with Microsoft ASP.NET Web Optimization Framework http://nuget.org/packages/Microsoft.AspNet.Web.Optimization/1.0.0-beta3 and I'm receiving this error.

Method not found: 'Void System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: Method not found: 'Void System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'.

[MissingMethodException: Method not found: 'Void System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'.] App.MVC.BundleConfig.RegisterBundles(BundleCollection bundles) in C:...\App_Start\BundleConfig.cs:53 App.MVC.MvcApplication.Application_Start() in C:...\Global.asax.cs:47

[HttpException (0x80004005): Method not found: 'Void System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'.] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +4057141 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375

[HttpException (0x80004005): Method not found: 'Void System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700896 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869125

This the code I'm using:

in global.asax.cs

protected void Application_Start()
{
    ...
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    ...

and then in App_Start/BundleConfig.cs

using System.Web.Optimization;

namespace App.MVC.App_Start
{
public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new Bundle("~/scripts/packed.js", new JsMinify()).Include(
                    // jquery
                    "~/Scripts/jquery-1.7.1.js",
                    "~/Scripts/jquery-ui-1.8.17.js",
                    "~/Scripts/jquery.validate.js",
                    "~/Scripts/jquery.validate.unobtrusive.js",
                    "~/Scripts/jquery.unobtrusive-ajax.js"));

        bundles.Add(new Bundle("~/content/css/packed.css", new CssMinify()).Include(
                    // reset
                    "~/Content/css/cssreset-min.css", 
                    "~/Content/css/cssfonts-min.css",

                    // themes
                    "~/Content/themes/base/jquery-ui-1.8.16.custom.css",

                    // site
                    "~/Content/css/Site.css"));
    }
}
}

I'm also using Azure with this project and funny this is, first time when I start Azure, I get this error. Then when I just rebuild MVC project and refresh page, it works.

How would I approach solving this?

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
FrEaKmAn
  • 1,785
  • 1
  • 21
  • 47
  • Can you post the code that's causing this error? – RickAndMSFT Jun 20 '12 at 23:37
  • Why are you using new JsMinify()) and new CssMinify()) ? Just follow the pattern in the RC generated App_Start\BundleConfig.cs code and my tutorial http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification – RickAndMSFT Jun 22 '12 at 18:52

1 Answers1

4

I received the same error when I referenced the wrong package via

  Install-Package Microsoft.Web.Optimization -Version 1.0.0-beta -Pre

resolved by referencing correct newer package

Install-Package Microsoft.Web.Optimization -Pre 
cmsjr
  • 56,771
  • 11
  • 70
  • 62
  • I'm not sure if this is the right package? Does the code I added work? – FrEaKmAn Jun 21 '12 at 18:43
  • It builds and compiles fine. You did use the second package? What error are you getting with it installed? – cmsjr Jun 21 '12 at 19:37
  • PM> Install-Package Microsoft.Web.Optimization -Pre Attempting to resolve dependency 'Microsoft.AspNet.Web.Optimization (≥ 1.0.0-beta2)'. Attempting to resolve dependency 'Microsoft.Web.Infrastructure (≥ 1.0.0)'. Attempting to resolve dependency 'WebGrease (≥ 1.0.0)'. 'Microsoft.Web.Optimization 1.0.0-beta2' already installed. Successfully added 'Microsoft.AspNet.Web.Optimization 1.0.0-beta3' to App.MVC. This just adds the same package I had.. – FrEaKmAn Jun 22 '12 at 10:53
  • See if you can declare A ScriptBundle, if you can't I'd say this is still a reference problem at some level because beta2 and later should have the constructor you need, but beta1 didn't have ScriptBundle defined yet. – cmsjr Jun 22 '12 at 15:03
  • ScriptBundle applies it automatically in its constructor. – cmsjr Jun 22 '12 at 15:31
  • Actually I get error Could not load type 'System.Web.Optimization.ScriptBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. but System.Web.Optimization is pointing to beta3 – FrEaKmAn Jun 22 '12 at 16:14
  • That is still the correct version and token for beta3. Compare the System.Web.Optimization.dll located where the reference properties say it resides to the version in your bin directory. If Visual Studio shows the type as if it is valid, but it fails when you try to run it, there's an older version somewhere in the mix. Clean and Build wouldn't hurt either. – cmsjr Jun 22 '12 at 17:03
  • The problem was that my solution has multiple projects and on of the projects still had old reference - a rookie mistake. – FrEaKmAn Jun 23 '12 at 19:50
  • Same problem here,in order to fix "Scripts not exist" error I installed new package but things got worse. – Mohsen Afshin Jul 10 '12 at 17:03