2014-02-16 42 views
36

我想包括像這樣的目錄中的所有文件數組的邊界之外:StyleBundle指數

bundles.Add(new StyleBundle("~/Content/simpliq_css").Include(
    "~/Content/simpliq/*.css" 
)); 

但我得到這個錯誤Index was outside the bounds of the array

紅線是:

@Styles.Render("~/Content/simpliq_css")

[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.ParseElementName() +321 
    Microsoft.Ajax.Utilities.CssParser.ParseSimpleSelector() +54 
    Microsoft.Ajax.Utilities.CssParser.ParseSelector() +555 
    Microsoft.Ajax.Utilities.CssParser.ParseRule() +165 
    Microsoft.Ajax.Utilities.CssParser.ParseStylesheet() +186 
    Microsoft.Ajax.Utilities.CssParser.Parse(String source) +946 
    Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String source, CssSettings settings, CodeSettings scriptSettings) +439 
    Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String source, CssSettings settings) +73 
    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) +1030 
    System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) +75 
    System.Web.Optimization.Styles.RenderFormat(String tagFormat, String[] paths) +293 
    System.Web.Optimization.Styles.Render(String[] paths) +51 
    ASP._Page_Areas_Admin_Views_Shared__Layout_cshtml.Execute() in f:\MyProjects\Fables\Fables\Fables.Web\Areas\Admin\Views\Shared\_Layout.cshtml:8 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271 
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +120 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +145 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) +41 
    System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +335 
    System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42 
    System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45 
    System.Web.WebPages.WebPageBase.Write(HelperResult result) +53 
    System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178 
    System.Web.WebPages.WebPageBase.PopContext() +347 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +154 
    System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695 
    System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382 
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106 
    System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +321 
    System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +185 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40 
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 
    System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39 
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 
+0

請寄出異常的完整堆棧跟蹤! – nemesv

+0

嘗試將bundle名稱更改爲不同於〜/ bundles/css之類的目錄。 – Nexus23

+0

這沒有幫助 – FSou1

回答

89

問題出現在下一包的版本中年齡:

enter image description here

必須更新它,問題就解決了。

+26

對我來說,它只是更新webgrease。 我不需要更新Web Optimization Framework(我的版本:1.1.3)。 – Tobias

+0

你可以用你的軟件包管理器中的Install-Package WebGrease來更新它('Tools> NuGet Package Manager> Package Manager Console') – RPDeshaies

+2

或者從軟件包管理器控制檯更新軟件包,只需使用:Update-Package WebGrease -ProjectName YourWebProject – shekhar

0

請注意,這可能是由無效的JavaScript引起的。在編寫JavaScript時,我注意到我的包突然開始拋出這個消息。堆棧跟蹤顯示它正在炸燬「Microsoft.Ajax.Utilities.JSScanner.ScanTemplateLiteral」。事實證明,我無意中在我的JavaScript中添加了一個`(反引號)。刪除它導致一切再次工作。我正在運行Webgrease 1.6.0和Microsoft ASP.NET Web Optimization Framework 1.1.2。

當CSS中有一個反引號時,捆綁器不受影響。

12

我有同樣的問題,當我嘗試了不同的檢查我發現存在這樣我的CSS文件中的選擇導致問題:

.glyphicons圖標_: - 鄰預聚焦 ,.glyphicons-icon {background-image:url(../ images/glyphicons.png); }

看來,Microsoft.Ajax.Utilities.CssParser有一個與_: css選擇器的問題。我刪除了該行,它正在工作。

11

當試圖將JavaScript文件添加到StyleBundle時,可能會出現相同的錯誤。

2

我有同樣的錯誤。我的ASP.NET Web Optimization Framework已更新,但Bootstrap的版本是3.3.0。我將Bootstrap更新爲3.3.5,錯誤消失了。

0

在我的情況下,它只是一個額外的撇號「`」在一個js文件中。 ASP.NET似乎對這個特殊字符(Grave accent)很敏感。所以一定要檢查你的代碼是否有錯別字。