microsoft / ajaxmin

The Microsoft Ajax Minifier enables you to improve the performance of your Ajax applications by reducing the size of your Cascading Style Sheet and JavaScript files.
https://www.nuget.org/packages/AjaxMin
MIT License
33 stars 21 forks source link

Got object reference null issue when resolve the js file #22

Closed chucklu closed 1 year ago

chucklu commented 1 year ago

We have added a ScriptBundle of js file, and got exception

  bundles.Add(new ScriptBundle("~/admin/js").Include("js file path");

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Ajax.Utilities.Member.GetFunctionGuess(AstNode target) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.GuessAtName(AstNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(FunctionObject node) at Microsoft.Ajax.Utilities.FunctionObject.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(BinaryOperator node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.IfNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.IfNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.IfNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(FunctionObject node) at Microsoft.Ajax.Utilities.FunctionObject.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(CallNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(CallNode node) at Microsoft.Ajax.Utilities.CallNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.JSParser.InternalParse() 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, IEnumerable1 bundleFiles) at System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context) at System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath) at System.Web.Optimization.AssetManager.EliminateDuplicatesAndResolveUrls(IEnumerable1 refs) at System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) at ASP._Page_Views_SharedAdminLayout_cshtml.Execute() in _AdminLayout.cshtml:line 29 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.WebPages.WebPageBase.<>cDisplayClass40_0.b0(TextWriter writer) at System.Web.WebPages.WebPageBase.Write(HelperResult result) at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) at System.Web.WebPages.WebPageBase.PopContext() at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass3_1.b1(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<>c.b152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.<>c.b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

The file was downloaded from https://datatables.net/download/index

datatables.min.js.zip

chucklu commented 1 year ago

The above issue comes from WebGrease Microsoft.Ajax.Utilities public class Minifier packages\WebGrease.1.6.0\lib\WebGrease.dll

We're using Microsoft.AspNet.Web.Optimization,and it depends on WebGrease library.

source code https://webgrease.codeplex.com/ alternative tools https://github.com/dotnet/aspnetcore/issues/1604
Use NUglify or JSMin.NET.

chucklu commented 1 year ago

This issue happened in Process method of JsMinify class of System.Web.Optimization library.

    Minifier minifier = new Minifier();
                string content = minifier.MinifyJavaScript(response.Content, new CodeSettings
                {
                    EvalTreatment = EvalTreatment.MakeImmediateSafe,
                    PreserveImportantComments = false
                });

Minifier class located in WebGrease.dll, and error happened in MinifyJavaScript method of Minifier class

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Ajax.Utilities.Member.GetFunctionGuess(AstNode target) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.GuessAtName(AstNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(FunctionObject node) at Microsoft.Ajax.Utilities.FunctionObject.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(BinaryOperator node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.IfNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.IfNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(IfNode node) at Microsoft.Ajax.Utilities.IfNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(FunctionObject node) at Microsoft.Ajax.Utilities.FunctionObject.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.TreeVisitor.Visit(CallNode node) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(CallNode node) at Microsoft.Ajax.Utilities.CallNode.Accept(IVisitor visitor) at Microsoft.Ajax.Utilities.AnalyzeNodeVisitor.Visit(Block node) at Microsoft.Ajax.Utilities.JSParser.InternalParse() at Microsoft.Ajax.Utilities.Minifier.MinifyJavaScript(String source, CodeSettings codeSettings) at System.Web.Optimization.JsMinify.Process(BundleContext context, BundleResponse response)

similar issue https://github.com/trullock/NUglify/issues/36