Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 5 Bundle Error

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!

like image 341
GSeriousB Avatar asked Mar 12 '15 21:03

GSeriousB


People also ask

What are the two types of bundles in MVC 5?

You can see ScriptBundle and StyleBundle objects we are using for bundling the js and CSS types of files. ScriptBundle: is responsible for Script files i.e javascript (JS). StyleBundle: is responsible for stylesheet files i.e CSS.

How is bundling done in MVC?

Bundling and minification techniques were introduced in MVC 4 to improve request load time. Bundling allows us to load the bunch of static files from the server in a single HTTP request. In the above figure, the browser sends two separate requests to load two different JavaScript file MyJavaScriptFile-1.

What is BundleConfig Cs in ASP NET MVC?

By default, the MVC application's BundleConfig (located inside App_Start folder) comes with the following code − public static void RegisterBundles(BundleCollection bundles) { // Following is the sample code to bundle all the css files in the project // The code to bundle other javascript files will also be similar to ...

What is minification and bundling of files in MVC?

Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.


2 Answers

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.

like image 187
Tim Iles Avatar answered Oct 18 '22 20:10

Tim Iles


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.

like image 38
Jerry Avatar answered Oct 18 '22 19:10

Jerry