question

BryanValencia-7384 avatar image
0 Votes"
BryanValencia-7384 asked pedramsaharkhiz-6692 commented

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

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, List`1 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, List`1 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, List`1 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, IEnumerable`1 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"?

dotnet-aspnet-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YijingSun-MSFT avatar image
1 Vote"
YijingSun-MSFT answered pedramsaharkhiz-6692 commented

Hi @BryanValencia-7384 ,
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.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I´m geeting the same issue that @BryanValencia-7384. I done the changes, but still not load the boostraps elements

0 Votes 0 ·

hi @MrM-6871 ,

but still not load the boostraps elements

After you changing the bundles,if you have 404 errors causing that you can't load the load the boostraps elements?
You could check if you registered Bundles in the Global.asax.cs.Just like this:

  BundleConfig.RegisterBundles(BundleTable.Bundles);

Best regards,
Yijing Sun

0 Votes 0 ·
MrM-6871 avatar image MrM-6871 YijingSun-MSFT ·

Hi,
I have all the changes that you post before:

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

BundleConfig.RegisterBundles(BundleTable.Bundles);

But, the Index.cshtml still don´t have the boostraps element when build the app....looks like simple html page...don´t have the styles.

Regards.

PD: Image attached
121955-example.jpg


0 Votes 0 ·
example.jpg (16.5 KiB)
Show more comments

The BundleConfig was created in the pre-updated state when I created the MVC project.

0 Votes 0 ·
YijingSun-MSFT avatar image YijingSun-MSFT BryanValencia-7384 ·

Hi @BryanValencia-7384 ,
I suggest you could change the BundleConfig in the App_Start and then rebuild your solution.
Best regards,
Yijing Sun

0 Votes 0 ·
MilanJakovac-3420 avatar image
5 Votes"
MilanJakovac-3420 answered mfmorrissey-7472 commented

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 .


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It worked! Thanks

0 Votes 0 ·