-->

MVC 5 Bundle Error

2020-08-20 15:55发布

问题:

I have a big problem. I created an MVC 5 project and I cannot start it with default code. The problem is with the bundling. It stops in the Global.asax.cs/Application_Start method, on the BundleConfig.RegisterBundles(BundleTable.Bundles); line. It says "Method not found: '!!0[] System.Array.Empty()'." (System.MissingMethodException).

Here is the BundleConfig.cs code (default):

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/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 ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

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

I'm using VS 2015 Preview. What should I do/change?

Thanks!

回答1:

As Mrchief says in the comments, the problem is due to compiling against .NET 4.6, but it's not a bug: you can deploy the 4.6 RC runtime on your server if you choose to. If you're running in Azure, this option will probably not be available until 4.6 is officially released (i.e. not RC).

From http://blogs.msdn.com/b/dotnet/archive/2015/05/08/targeting-the-net-framework-4-6-rc.aspx:

your app will require the .NET Framework 4.6 (or later) to run. You will need to deploy the .NET Framework 4.6 RC

Safest for now is to not target 4.6 unless you really need it.



回答2:

This will occur if .NET 4.6 is not installed on the server. If you have your own web server (not Azure), you may get the installer here. Note - don't confuse the targeting pack with the actual .NET installer.