Sobieck Sobieck - 1 year ago 219
ASP.NET (C#) Question

ScriptBundle IncludeDirectory Length Maximum For Filenames?

Is there a maximum filename length in ASP.NET's ScriptBundle

method when search sub directories is enabled?

When I include a file that has a long descriptive name and then launch the project my Visual Studio 2013 Professional starts to load everything, but once it starts to load the .js files VS just hangs without ever loading the website in the browser. However, when I trim the longer names of the .js files in the folders that I've used
it seems to work well. But I could be off. Has anyone else encountered this sort of behavior? How did you fix it?

Simplified Example

public static void RegisterBundles(BundleCollection bundles)
bundles.Add(new ScriptBundle("~/bundles/angularapp")
.IncludeDirectory("~/AngularApp", "*.js", true));


  • AngularApp

    • Next Folder

      • Contains SuperLongNameOfFileToTellMeWhatItDoes.js -- Doesn't work

      • Contains ShortName.js -- Seems to Work

Obviously, my project contains a lot more files and a much deeper file structure than this. But I'm trying to transition to
from explicitly including each .js file in a very large

Answer Source

I have a structure like this:

enter image description here

I tried to use this:

    bundles.Add(new ScriptBundle("~/bundles/myScripts").Include(
        "~/Scripts for monei/my_scripts.js"
        // WARN: this one fail
        .IncludeDirectory("~/Scripts for myapp/Angular", "*.js", true)

It fails. If I use IncludeDirectory in a separate rows it fails on:


The Angular directory contains only .js files and there are not empty directories neither strange characters in the names apart from the underscore.

I solved using the .IncludeDirectory sintax without the searchSubdirectories parameter, a call for every subdirectories.

ScriptBundle myBundle = bundles.GetBundleFor("~/bundles/myScripts") as ScriptBundle;
myBundle.IncludeDirectory("~/Scripts for myapp/Angular/controllers", "*.js");
myBundle.IncludeDirectory("~/Scripts for myapp/Angular/directives", "*.js");

It works, so the paths and files are correct. It is just the method that search in the subfolders that fails.

I assume you are calling


in Application_Start of the Global.asax .

To find what is the error try to attach the debugger and put a break point somewhere before that call. Probably you'll have a System.Web.HttpException (actually one for every subfolder) that says:

{"Invalid file name for file monitoring: 'D:\Programming\Web sites\mywebapp\Scripts for myapp\Angular\controllers'. Common reasons for failure include:\r\n- The filename is not a valid Win32 file name.\r\n- The filename is not an absolute path.\r\n- The filename contains wildcard characters.\r\n- The file specified is a directory.\r\n- Access denied."}

In my case none of these reasons seemsvalid, I can register the content of the subfolders using the method without the "subfolder search". To make Applcation_Start fired again just add/remove a blank line in web.config.

Note that this exception does not block the ASP Engine and in my case the page is rendered in the browser, you just doesn't see the error. I noticed it because in the Application_Start I do other operations and that are not executed.

I don't know the real cause of the error, but this is how you can find it and the workaround that works for me.

Note. To exclude the Jasmine test files I use this (after the other commands): bundles.IgnoreList.Ignore("*_jasmine.js", OptimizationMode.Always);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download