Home > Blockchain >  Visual Studio 2022 MVC Object Reference Error with @Script.Render(~/bundles/bootstrap)
Visual Studio 2022 MVC Object Reference Error with @Script.Render(~/bundles/bootstrap)

Time:03-09

I'm a beginner college student working on a group project in MVC. Things had been going relatively well until our most recent code update.

When testing the app (locally) in browser, the app throws this error:

Object Reference Error

Stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteralProperty(Boolean isBindingPattern)  944
   Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteral(Boolean isBindingPattern)  164
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  2591
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseExpressionList(JSToken terminator)  408
   Microsoft.Ajax.Utilities.JSParser.ParseMemberExpression(AstNode expression, List`1 newContexts)  106
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  3074
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement)  41
   Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)  1474
   Microsoft.Ajax.Utilities.JSParser.ParseBlock()  147
   Microsoft.Ajax.Utilities.JSParser.ParseArrowFunction(AstNode parameters)  200
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  3057
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseExpressionList(JSToken terminator)  408
   Microsoft.Ajax.Utilities.JSParser.ParseMemberExpression(AstNode expression, List`1 newContexts)  106
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  3074
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement)  41
   Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)  1474
   Microsoft.Ajax.Utilities.JSParser.ParseBlock()  147
   Microsoft.Ajax.Utilities.JSParser.ParseIfStatement()  528
   Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(Block body)  43
   Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)  1083
   Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteralProperty(Boolean isBindingPattern)  1168
   Microsoft.Ajax.Utilities.JSParser.ParseObjectLiteral(Boolean isBindingPattern)  164
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  2591
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseVarDecl(JSToken inToken)  407
   Microsoft.Ajax.Utilities.JSParser.ParseVariableStatement()  586
   Microsoft.Ajax.Utilities.JSParser.ParseFunctionBody(Block body)  43
   Microsoft.Ajax.Utilities.JSParser.ParseFunction(FunctionType functionType, Context fncCtx)  1083
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  2626
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  2329
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseExpressionList(JSToken terminator)  408
   Microsoft.Ajax.Utilities.JSParser.ParseMemberExpression(AstNode expression, List`1 newContexts)  106
   Microsoft.Ajax.Utilities.JSParser.ParseLeftHandSideExpression(Boolean isMinus)  3074
   Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)  1090
   Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement)  41
   Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)  1474
   Microsoft.Ajax.Utilities.JSParser.ParseStatements(Block block)  76
   Microsoft.Ajax.Utilities.JSParser.InternalParse()  848
   Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript(String source, CodeSettings codeSettings)  805
   System.Web.Optimization.JsMinify.Process(BundleContext context, BundleResponse response)  115
   System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable`1 bundleFiles)  325
   System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context)  59
   System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath)  213
   System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 assets)  421
   System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths)  34
   ASP._Page_Views_Shared__Layout_cshtml.Execute() in C:\Users\tyler_sfm3fox\Desktop\Capstone\InTurn\InTurn\Views\Shared\_Layout.cshtml:46
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy()  252
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy()  148
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)  122
   System.Web.WebPages.<>c__DisplayClass40_0.<RenderPageCore>b__0(TextWriter writer)  309
   System.Web.WebPages.WebPageBase.Write(HelperResult result)  108
   System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)  89
   System.Web.WebPages.WebPageBase.PopContext()  310
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)  378
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)  91
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)  795
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)  81
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult)  188
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)  38
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState)  29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  73
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)  52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  39
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)  38
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState)  43
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  73
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)  38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  431
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)  75
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  158

I believe this is either an issue with BundleConfig.cs file or the Bootstrap.js file. I'm not entirely sure where or how to even look for the root cause.

I've looked around this site at similar questions and a common solution was to change

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

to

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

That stopped the exception from happening, but the bootstrap elements were gone.

Before

After

I've been hitting my head against a wall trying to find out what's going on.

CodePudding user response:

So someone on the team must have updated Bootstrap and jQuery. Our project template did not like that. I went ahead and downgraded to the default Bootstrap and jQuery versions that came with the ASP.Net Web App (.net Framework) template and that fixed the issue.

Though I am curious in learning how to maybe address this issue without having to downgrade.

Happy to say though, that the project is up and running.

  • Related