各コントローラーには(同じ名前のコントローラーを持つ)フォルダーがあり、アクションごとにスクリプトファイルがあります。
ファイルごとに、次のパターンに従ってバンドルを作成しています: "〜/ Scripts/Controllers/{controller-name}/{filename-without-extension}"
bundles.IncludePerFile(new DirectoryInfo(server.MapPath("~/Scripts/Controllers")), "~/Scripts/Controllers/{0}/{1}",
(dir,file) => string.Format("~/Scripts/Controllers/{0}/{1}", dir, Path.GetFileNameWithoutExtension(file)), "*.js");
IncludePerFile
は、このタスクを実行するために作成した拡張メソッドです
次に、次の1つのバンドル:~/Scripts/Controllers/processos/pasta
存在する必要があります!
そしてこれを確認するために:
これまでのところ正しいです!バンドルが存在します!
アプリケーションを実行すると、次のエラーが発生します。
これを変更した場合:
@Scripts.Render("~/Scripts/Controllers/processos/pasta")
これに:
@Scripts.Render("~/Scripts/Controllers/processos/pasta.js")
エラーは発生しません。ただし、事実上バンドルがあるため、ファイルは縮小されません。 (私はすでにリリースモードにしてアプリケーションを公開しています!)
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Source Error:
Line 3: @section js {
Line 4: @*@Scripts.Render("~/Scripts/Controllers/processos/Pasta.js", "~/Scripts/Controllers/processos/display.js")*@
Line 5: @Scripts.Render("~/Scripts/Controllers/processos/pasta")
Line 6: @Scripts.Render("~/Scripts/Controllers/processos/display.js")
Line 7:
Source File: w:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\CreditoImobiliarioBB.Web\Views\processos\display.cshtml Line: 5
Stack Trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.String.get_Chars(Int32 index) +0
Microsoft.Ajax.Utilities.CssParser.Append(Object obj, TokenType tokenType) +402
Microsoft.Ajax.Utilities.CssParser.AppendCurrent() +74
Microsoft.Ajax.Utilities.CssParser.SkipToClose() +744
Microsoft.Ajax.Utilities.CssParser.SkipToEndOfStatement() +232
Microsoft.Ajax.Utilities.CssParser.ParseRule() +574
Microsoft.Ajax.Utilities.CssParser.ParseStylesheet() +1235
Microsoft.Ajax.Utilities.CssParser.Parse(String source) +897
Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String source, CssSettings settings) +419
System.Web.Optimization.CssMinify.Process(BundleContext context, BundleResponse response) +302
System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable`1 bundleFiles) +207
System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) +355
System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context) +104
System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath) +254
System.Web.Optimization.AssetManager.EliminateDuplicatesAndResolveUrls(IEnumerable`1 refs) +435
System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 assets) +1029
System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) +75
System.Web.Optimization.Scripts.RenderFormat(String tagFormat, String[] paths) +292
System.Web.Optimization.Scripts.Render(String[] paths) +51
この質問でも同じエラーが発生しました: StyleBundleインデックスが配列の範囲外でした
答えは非常に簡単です。Microsoft Web Optimization
&WebGrease
パッケージを更新する必要があります(現時点では1.1.2および1.6.0バージョン)
私は同じ問題を抱えていましたが、別のチェックを試みたところ、cssファイルにこのような問題の原因となるセレクターがあることがわかりました。
。glyphicons-icon _:-o-prefocus 、. glyphicons-icon {background-image:url(../ images/glyphicons.png); }
microsoft.Ajax.Utilities.CssParserに_ : cssセレクターに問題があるようです。行を削除しましたが、機能しています。
私はあなたのすべての要素を確認します
IncludePerFile(new DirectoryInfo(server.MapPath("~/Scripts/Controllers")), "~/Scripts/Controllers/{0}/{1}",
(dir,file) => string.Format("~/Scripts/Controllers/{0}/{1}", dir, Path.GetFileNameWithoutExtension(file)), "*.js")
作成されたバンドルを、あなたが入れていると思うものとまったく同じように入れています。
間違ったタイプのファイルがバンドルに含まれていると、実行時にこのエラーが発生しました。つまり.
@Styles.Render("~/bundles/myStyleBundle");
実際にはJavaScriptファイルが含まれています。
私はちょうど同様の問題に遭遇しました。 VS2013とMVC5を使用していて、Bootswatchのテーマを使用するためにBootstrap v3.0.1に更新していました。最新のBootstrapダウンロードすると、サイトは正常に機能しているように見えました。次に、BootswatchサイトからSlateのCSSを取得し、新しいスタイルシートで使用し、StyleBundleで変更してソリューションを構築しました。実行すると、「インデックスは配列の境界」エラー。bootstrap.cssに戻ると、正常に機能しました。
次に、NuGetパッケージマネージャーを使用してすべてのパッケージを更新しました... VS 2013をインストールしたばかりで、まだすべてを更新していません。ソリューションとワラを再構築しました。うまく機能します。だから私はあなたのパッケージの更新に賛成票を投じます。
Nugetライブラリの一部を更新する必要がある場合があります。 WebGreaseを更新してみてください