Search code examples
asp.net-mvcvisual-studio-2012lessbundle

Less bundle is throwing a StackOverflow exception


I'm trying to bundle some .less files in VS 2012. I have installed the BundleTransformer which also installs dotless.

Here's my BundleConfig.cs

using System.Web;
using System.Web.Optimization;
using BundleTransformer.Core.Orderers;
using BundleTransformer.Core.Transformers;

namespace TrainerRoad.Web
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            var cssTransformer = new CssTransformer();
            var jsTransformer = new JsTransformer();
            var nullOrderer = new NullOrderer();

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

            // 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-*"));

            var lessBundle = new StyleBundle("~/bundles/css").Include(
                "~/assets/css/*.less");

            lessBundle.Transforms.Add(cssTransformer);
            lessBundle.Orderer = nullOrderer;

            bundles.Add(lessBundle);

        }
    }
}

When I add

@Styles.Render("~/bundles/css")

To my head section I get

An unhandled exception of type 'System.StackOverflowException' occurred in System.Web.dll

I've tried making it just a Bundle instead of a StyleBundle and that didn't help either. I can hit the less files directly and they serve up correcting (that uses the bundle transformer). I've also tried specifying each file instead of using the *.less syntax.

How do I bundle these LESS files correctly?


Solution

  • You could change the bondule and instead load the LESS files load the CSS files generated by the Web Essentials you can configuire the CSS compilation.