Is there a maximum filename length in ASP.NET's ScriptBundle .IncludeDirectory 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 .IncludeDirectory 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));
}
Folders
- AngularApp
- Next Folder
- Contains SuperLongNameOfFileToTellMeWhatItDoes.js -- Doesn't work
- Contains ShortName.js -- Seems to Work
- Next Folder
Obviously, my project contains a lot more files and a much deeper file structure than this. But I'm trying to transition to .IncludeDirectory from explicitly including each .js file in a very large .Include block.
I have a structure like this:
I tried to use this:
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.
It works, so the paths and files are correct. It is just the method that search in the subdirectories 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 subdirectory) that says:
In my case none of these reasons seems valid, I can register the content of the subfolders using the method without the "subfolder search". (Tip. To make Application_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 them 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.
Tip. To exclude the Jasmine test files I use this (after the other commands): bundles.IgnoreList.Ignore("*_jasmine.js", OptimizationMode.Always);