3

我正在使用最新的 MVC4-RC (.net 4.0) 和 Microsoft ASP.NET Web 优化框架http://nuget.org/packages/Microsoft.AspNet.Web.Optimization/1.0.0-beta3我收到了这个错误。

找不到方法:'无效 System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.MissingMethodException:找不到方法:'Void System.Web.Optimization.Bundle..ctor(System.String, System.Web.Optimization.IBundleTransform[])'。

[MissingMethodException:找不到方法:'Void System.Web.Optimization.Bundle..ctor(System.String,System.Web.Optimization.IBundleTransform[])'。] App.MVC.BundleConfig.RegisterBundles(BundleCollection bundles)在C :...\App_Start\BundleConfig.cs:53 App.MVC.MvcApplication.Application_Start() 在 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 应用程序)+4057141 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext 上下文,MethodInfo[] 处理程序)+191 System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序,IntPtr appContext,HttpContext 上下文)+ 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

这是我正在使用的代码:

在 global.asax.cs

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

然后在 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"));
    }
}
}

我也在这个项目中使用 Azure,有趣的是,当我第一次启动 Azure 时,我得到了这个错误。然后,当我重建 MVC 项目并刷新页面时,它就可以工作了。

我将如何解决这个问题?

4

1 回答 1

4

当我通过引用错误的包时,我收到了同样的错误

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

通过引用正确的较新包解决

Install-Package Microsoft.Web.Optimization -Pre 
于 2012-06-21T17:51:44.307 回答