0

I made some refactoring on my ASP.NET App (Namespaces renaming mainly) and here it is, forst razor page I launch isn't working. I have a NullReferenceException in Webgrease.

Exception looks like to occur when I

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

Few lines before, I insert css ut there is no Exception on it

@Styles.Render("~/Content/css")

Here is the bundle config

public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
}}

And there is tghe Global.asax part that interest us:

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // For logging
            //SetupSemanticLoggingApplicationBlock();
        }
}

Here is the stack trace:

à Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) à Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) à Microsoft.Ajax.Utilities.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus) à Microsoft.Ajax.Utilities.JSParser.ParseExpression(AstNode leftHandSide, Boolean single, Boolean bCanAssign, JSToken inToken) à Microsoft.Ajax.Utilities.JSParser.ParseExpressionStatement(Boolean fSourceElement) à Microsoft.Ajax.Utilities.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment) à Microsoft.Ajax.Utilities.JSParser.ParseStatements(Block block) à Microsoft.Ajax.Utilities.JSParser.InternalParse() à Microsoft.Ajax.Utilities.JSParser.Parse(DocumentContext sourceContext) à Microsoft.Ajax.Utilities.JSParser.Parse(DocumentContext sourceContext, CodeSettings settings) à Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript(String source, CodeSettings codeSettings) à System.Web.Optimization.JsMinify.Process(BundleContext context, BundleResponse response) à System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable1 bundleFiles) à System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) à System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context) à System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath) à System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable1 assets) à System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) à System.Web.Optimization.Scripts.RenderFormat(String tagFormat, String[] paths) à System.Web.Optimization.Scripts.Render(String[] paths) à ASP._Page_Views_Account_Login_cshtml.Execute() dans c:\Users\xxx\Views\Account\Login.cshtml:ligne 80 à System.Web.WebPages.WebPageBase.ExecutePageHierarchy() à System.Web.Mvc.WebViewPage.ExecutePageHierarchy() à System.Web.WebPages.StartPage.RunPage() à System.Web.WebPages.StartPage.ExecutePageHierarchy() à System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) à System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) à System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) à System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) à System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) à System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) à System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

Both Bundle and Global are in the same namespace.

What did I forget?

Global.asax, BundleConfig and then startup are firing when I breakpoint them si I'm little surprised!

EDIT: When I remove

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

it is working properly (well jquery is not loaded but the app is running), so I expect this is an isssue with the definition of ressources of jquery? How to test it?

Here is sources when I didn't include this Bundle: enter image description here

Here's the interesting part of the "Script" folder:

enter image description here

EDIT 2:

I've done new tests but this is really strange.

I've added non-dynamic path:

bundles.Add(new ScriptBundle("~/bundles/yeeeep").Include(
                        "~/Scripts/jquery-2.2.3.js",
                        "~/Scripts/jquery-ui-1.11.4.js"
                        ));

And include it in my cshtml.

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

The result is that I got a 404 for this ressource!

The file is real (valid, I've opened it) and is located in

\Main\Source\PROJECT.WEB\Scripts\jquery-2.2.3.js

So path looks great but it doesn't work

EDIT 3:

I go mad...

<script src="~/Scripts/jquery-2.2.3.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>

Works but that (with @Scripts.Render("~/bundles/yeeeep")) doesn't:

bundles.Add(new ScriptBundle("~/bundles/yeeeep").Include(
                        "~/Scripts/jquery-2.2.3.js",
                        "~/Scripts/jquery-ui-1.11.4.js"
                        ));
clement
  • 4,204
  • 10
  • 65
  • 133
  • Is that file deployed to your web site? (`~/Scripts/jquery-{version}.js`) – Igor Dec 08 '17 at 15:53
  • @Igor Well, If I let the Render("~/bundles/jquery"), I've the Exception'syellow screen. If I remove the bundle, I didn't see the bundle that I didn't included. On the another hand, I have a second Script that is in a undle and this is included and working – clement Dec 08 '17 at 15:58
  • That is not my question. My question is: Does the file, `Scripts/jquery-xxx.js`, exist in the directory from where the web application is running? If not then it can't be bundled and you will get an exception. If it does exist then perhaps it's something else. – Igor Dec 08 '17 at 16:00
  • @Igor yes there are files (see edited question) – clement Dec 08 '17 at 16:03
  • @Igor: see my second edit on iinitial Question! Thanks – clement Dec 08 '17 at 16:25
  • Try hard coding the version number to see if that is the reason it is not found. – Igor Dec 08 '17 at 16:28
  • I've done this and it doesn't impress me... What a strange situation! (see edit 3) – clement Dec 08 '17 at 16:31
  • Make sure your page doesn't render with cached references by open your page in an incognito tab of chrome for example. Also consider your bundles paths will be rendered in published mode of your website if you are testing locally. – Milad Rashidi Dec 08 '17 at 17:44

0 Answers0