@Scripts.Render("~/bundles/bootstrap") fails

Bryan Valencia 186 Reputation points
2021-08-05T04:37:48.02+00:00

VS 2019
Created an MVC APP
Updated all the outdated NuGet packages.

Now in my layout page:

@Scripts.Render("~/bundles/bootstrap")
...gives...
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=WebGrease
StackTrace:
at Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteralProperty(Boolean isBindingPattern)
at Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteral(Boolean isBindingPattern)
at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseExpressionList(JSToken terminator)
at Microsoft.Ajax.Utilities.JSParser.ParseMemberExpression(AstNode expression, List1 newContexts) at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement) at Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) at Microsoft.Ajax.Utilities.JSParser.ParseBlock() at Microsoft.Ajax.Utilities.JSParser.ParseArrowFunction(AstNode parameters) at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseExpressionList(JSToken terminator) at Microsoft.Ajax.Utilities.JSParser.ParseMemberExpression(AstNode expression, List1 newContexts)
at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement)
at Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)
at Microsoft.Ajax.Utilities.JSParser.ParseBlock()
at Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)
at Microsoft.Ajax.Utilities.JSParser.ParseIfStatement()
at Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)
at Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(Block body)
at Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)
at Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteralProperty(Boolean isBindingPattern)
at Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteral(Boolean isBindingPattern)
at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseVarDecl(JSToken inToken)
at Microsoft.Ajax.Utilities.JSParser.ParseVariableStatement()
at Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)
at Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(Block body)
at Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)
at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseExpression(Boolean single, JSToken inToken)
at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
at Microsoft.Ajax.Utilities.JSParser.ParseExpressionList(JSToken terminator)
at Microsoft.Ajax.Utilities.JSParser.ParseMemberExpression(AstNode expression, List1 newContexts) at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseExpression(Boolean single, JSToken inToken) at Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) at Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement) at Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) at Microsoft.Ajax.Utilities.JSParser.ParseStatements(Block block) at Microsoft.Ajax.Utilities.JSParser.InternalParse() at Microsoft.Ajax.Utilities.JSParser.Parse(DocumentContext sourceContext) at Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript(String source, CodeSettings codeSettings) at System.Web.Optimization.JsMinify.Process(BundleContext context, BundleResponse response) at System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable1 bundleFiles)
at System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context)
at System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context)
at System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath)
at System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 assets)
at System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths)
at System.Web.Optimization.Scripts.RenderFormat(String tagFormat, String[] paths)
at System.Web.Optimization.Scripts.Render(String[] paths)
at ASP._Page_Views_Shared__Layout_cshtml.Execute() in C:\Users\Bryan Valencia\Documents\Projects\MVCWizardFail\MVCWizardFail\Views\Shared_Layout.cshtml:line 39

  This exception was originally thrown at this call stack:
    [External Code]
    ASP._Page_Views_Shared__Layout_cshtml.Execute() in _Layout.cshtml

There is a ~/bundles/bootstrap in BundleConfig, which references ~/Scripts/bootstrap.js which is also there.

Is this a valid argument for "never update your modules"?

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-01-09T18:00:39.73+00:00

    Bootstrap 4 & 5 use newer syntax. You need to update your bundling software to one that support current css and JavaScript syntax. It looks like you are using system.web.optimization, which hasn’t been updated since 2014, so it does not appear an update exists for it.

    As .net 4.* framework no longer gets feature updates, it’s unlikely to get support for newer css and JavaScript syntax. You can switch a different bundler that is better maintained. There are many node based solutions, which you can use in the the build rather than at runtime.

    Or maybe it is time to upgrade to .net 6 if you want current feature support.

    0 comments No comments

  2. Mickael D 1 Reputation point
    2022-01-14T10:49:13.427+00:00

    Hello,

    finally, i migrate to bootstrap 5 and embed the link without bundle function but directly in the layer page with the render function. @Scripts.Render("~/Scripts/bootstrap.min.js")
    @Scripts.Render("~/Scripts/jquery-3.6.0.min.js")

    I use .net framework 4.7.2 because it is the version of my host.
    But i would to check it and microsoft page indicated this version is good for my environment.
    https://dotnet.microsoft.com/en-us/download/visual-studio-sdks.

    It's ready now.

    When my project is profitable, I recruit an expert :-)

    Thank you for your opinions.
    Mick

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.