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

Bryan Valencia 181 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"?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,250 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Milan Jakovac 66 Reputation points
    2021-08-09T19:29:06.513+00:00

    In Boundle.Config instead

    bundles.Add(new ScriptBundle("~/bundles/mybundle").Include(
    

    try

    bundles.Add(new Bundle("~/bundles/mybundle").Include(
    

    Worked for me after I update bootstrap from version 3 to 5 in my newest .NET MVC project .

    13 people found this answer helpful.

  2. Yijing Sun-MSFT 7,066 Reputation points
    2021-08-05T08:58:13.907+00:00

    Hi @Bryan Valencia ,
    How do you write in the BundleConfig? Maybe you could check your BundleConfig.You could change ScriptBundle to Bundle.Just like this:

    bundles.Add(new Bundle("~/bundles/bootstrap").Include(  
                          "~/Scripts/bootstrap.js",  
                          "~/Scripts/respond.js"));  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    9 people found this answer helpful.

  3. MikeB2021 1 Reputation point
    2021-12-08T01:34:20.58+00:00

    I am having the same issue, have tried all the above fix actions...still have the same problem described.

    Anyone get this one solved?

    0 comments No comments

  4. Bruce (SqlWork.com) 55,366 Reputation points
    2021-12-08T15:55:47.707+00:00

    To perform minimization the bundler must parse the files. The error means there is a syntax error in the input files to the bundler.

    note: you could detect the offending file by removing one at a time.

    also check that you have the latest nuget package for web grease, so that it supports the latest syntax,

    0 comments No comments

  5. Mickael D 1 Reputation point
    2022-01-08T13:19:20.683+00:00

    Hello team,

    I used the default ASP.NET MVC C# template in visual studio.
    The template use the boostrap v3. The migration is ok until to v4.6.1.

    After the v5, @Scripts.Render generates an exception.
    I try to rollback only bootstrap.js file, i don't have exception. The problem is link with content of file.
    I try to change ScriptBundle by Bundle. I don't have exception.

    Now, i rebuild the application and cleanup the cache of navigator. The display page is not good.
    Devtools send an error on loading of bootstrap.min.js.map.

    DevTools n’a pas pu charger le mappage de source : Désolé... Nous n’avons pas pu charger du contenu pour https://xxx.domain.fr/bundles/bootstrap.min.js.map:Erreur HTTP : code de statut 404,net::ERR_HTTP_RESPONSE_CODE_FAILURE

    I think, it is necessary to review the NuGet package.
    For the moment, I canceled the migration.

    What can I change?

    Happy new year,
    Mick

    0 comments No comments