在.Net MVC中从Bootstrap 3.7更新到5.0.2产生错误-System.NullReferenceException [英] Update From Bootstrap 3.7 to 5.0.2 in .net mvc producing Error- System.NullReferenceException

查看:0
本文介绍了在.Net MVC中从Bootstrap 3.7更新到5.0.2产生错误-System.NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我卸载了.Net MVC应用程序附带的基本引导程序模板,并从NuGetPackage Manager安装了引导程序5.0.2。现在我在运行时遇到了这个问题(构建正在成功进行):

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 D:C# ProjectscvcvViewsShared\_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

这是My_Layout.cshtml文件:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

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

中出错

这是BundleConfig.cs文件:

using System.Web;
using System.Web.Optimization;

namespace cv
{
    public class BundleConfig
    {
        // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

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

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }
    }
}

推荐答案

我们替换了以下内容:

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

使用:

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

这篇关于在.Net MVC中从Bootstrap 3.7更新到5.0.2产生错误-System.NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆