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, IEnumerable
1 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(IEnumerable
1 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(IList
1 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:
Here's the interesting part of the "Script" folder:
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"
));