gpt4 book ai didi

c# - Mvc BundleConfig 缩小 ="false"问题

转载 作者:行者123 更新时间:2023-11-30 17:49:11 36 4
gpt4 key购买 nike

我正在使用 Tom DuPonts MvcBundler,遵循他的指南:http://www.tomdupont.net/2012/03/configuring-bundles-in-mvc-4.html

我的配置文件里有这个

<add bundlePath="~/js/shared" minify="false">
<directories>
<add directoryPath="~/Scripts/Shared" searchPattern="*.js"></add>
</directories>
</add>

这会抛出这个错误

Server Error in '/' Application.

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 59: @Html.JsBundle("~/js/types")
Line 60: @Html.JsBundle("~/js/libraries")
Line 61: @Html.JsBundle("~/js/shared") <-------- Offending line

删除

minify="false"

或更新为

minify="true"

允许应用程序正常工作。

有没有办法不对使用此扩展名的一组文件使用缩小?

完整的堆栈跟踪

[NullReferenceException: Object reference not set to an instance of an object.]
System.Object.GetType() +0
System.Web.Optimization.DefaultBundleBuilder.BuildBundleContent(Bundle bundle, BundleContext context, IEnumerable`1 files) +381
System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) +282
System.Web.Optimization.Bundle.GetBundleUrl(BundleContext context, Boolean includeContentHash) +66
System.Web.Mvc.HtmlHelperExtensions.ReferenceBundle(HtmlHelper helper, String bundlePath, TagBuilder baseTag, String key) +142
ASP._Page_Views_Shared_Layouts_Default__Layout_cshtml.Execute() in Web\Views\Shared\Layouts\Default\_Layout.cshtml:61
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +233
System.Web.WebPages.WebPageBase.PopContext() +291
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

编辑:

将库更新到 2.2.0 后,我现在得到这个错误

Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<dynamic>' 
does not contain a definition for 'CssBundle' and no extension method
'CssBundle' accepting a first argument of type
'System.Web.Mvc.HtmlHelper<dynamic>' could be found (are you missing a
using directive or an assembly reference?)

Line 19: <link rel="icon" href="/Content/images/favicon.ico">
Line 20:
Line 21: @Html.CssBundle("~/css/bootstrap")

最佳答案

这应该在 v2.2.0 ( https://www.nuget.org/packages/MvcBundleConfig/2.2.0 ) 中修复

仅供引用:这个包很旧,需要更新。我将尝试尽快发布一个 3.0,它增加了对 Bundle Transformer 的支持。 ( https://bundletransformer.codeplex.com/ )

private static void AddBundleConfiguration<T>(BundleCollection bundles, IEnumerable<BundleConfig> bundleConfigs)
where T : IBundleTransform, new()
{
foreach (var bundleConfig in bundleConfigs)
{
// The bug WAS here; it was passing in null instead of an empty array, thus the
// Bundle constructor params would have an array of one that contained a null.
var transform = bundleConfig.Minify
? new IBundleTransform[] { new T() }
: new IBundleTransform[0];

var bundle = String.IsNullOrWhiteSpace(bundleConfig.CdnPath)
? new Bundle(bundleConfig.BundlePath, transform)
: new Bundle(bundleConfig.BundlePath, bundleConfig.CdnPath, transform);

关于c# - Mvc BundleConfig 缩小 ="false"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22050807/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com