Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvcBundleConfig minify="false" issue

Tags:

c#

asp.net-mvc

I am using Tom DuPonts MvcBundler, following his guide here: http://www.tomdupont.net/2012/03/configuring-bundles-in-mvc-4.html

I have this in my config file

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

This throws this error

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

Removing

minify="false"

or updating to

minify="true"

Allows the application to work correctly.

Is there a way to not use minification for a set of files using this extension?

Full stack trace

[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

Edit:

After updating the library to 2.2.0, I now get this error

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")
like image 522
djbielejeski Avatar asked Mar 02 '26 19:03

djbielejeski


1 Answers

This should be fixed in v2.2.0 (https://www.nuget.org/packages/MvcBundleConfig/2.2.0)

FYI: This package is old and needs an update. I will try to release a 3.0 soon that adds support for 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);
like image 56
tdupont Avatar answered Mar 04 '26 09:03

tdupont



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!