aspnetcore: [dotnet-sdk-9.0.100-preview.7.24379.15] Fail to load page in nopCommerceNetCore app after retargeting it to .NET 9.0 with error: System.NullReferenceException: Object reference not set to an instance of an object.
Description
When retarget the 3rd party application to net9.0, build and run with the latest .NET 9 build, it failed to load page with error:
System.NullReferenceException: Object reference not set to an instance of an object. When retargeting it to net9.0 using dotnet-sdk-9.0.100-preview.5.24307.3, this issue does not reproduce.
Findings:
After debugging into the source code of application, we found the exception is thrown from NUglify nuget package, which is referenced by WebMarkupMin.NUglify nuget package.
And if we reference the NUglify and WebMarkupMin.NUglify nuget packages source code into application source code directly, we found the exception is thrown at JSParser.ParseUnaryExpression() method in JSParser.cs file (line 3665) from NUglify package.
The expr variable in line 3664 returns a null object, which result to the line 3665 get “Object reference not set to an instance of an object” exception:
expr = ParseUnaryExpression(out dummy, false); //It returns null
ast = new UnaryExpression(exprCtx.CombineWith(expr.Context)) //The null expr causes the error
{
Operand = expr,
OperatorContext = exprCtx,
OperatorToken = opToken
};
Reproduction Steps
Please get the repro machine information from Internal bug
1.Open “…\Source\nopCommerce\src\Presentation\Nop.Web\Nop.Web.csproj” with Visual Studio.
2. Retarget Nop.Web to net9.0.
<TargetFramework>net9.0</TargetFramework>
3. Build the app with dotnet-sdk-9.0.100-preview.7.24379.15.
4. Run the app.
5. Go to “https://localhost:56111/Admin/Order/List” on browser.(If need login, account and password refer to Internal bug)
6. Click “View” in order list.
Expected behavior
Page loading successfully
Actual behavior
Page loaded failed with errors:
System.NullReferenceException: Object reference not set to an instance of an object.
StackTrace:
System.NullReferenceException: Object reference not set to an instance of an object.
at NUglify.JavaScript.JSParser.ParseUnaryExpression(Boolean& isLeftHandSideExpr, Boolean isMinus)
at NUglify.JavaScript.JSParser.ParseExpressionStatement(Boolean fSourceElement)
at NUglify.JavaScript.JSParser.ParseStatement(Boolean fSourceElement, Boolean skipImportantComment)
at NUglify.JavaScript.JSParser.ParseStatements(BlockStatement block)
at NUglify.JavaScript.JSParser.InternalParse()
at NUglify.JavaScript.JSParser.Parse(DocumentContext sourceContext)
at WebMarkupMin.NUglify.NUglifyJsMinifier.Minify(String content, Boolean isInlineCode, Encoding encoding)
at WebMarkupMin.NUglify.NUglifyJsMinifier.Minify(String content, Boolean isInlineCode)
at WebMarkupMin.Core.GenericHtmlMinifier.ProcessEmbeddedScriptContent(MarkupParsingContext context, String content, String contentType)
at WebMarkupMin.Core.GenericHtmlMinifier.EmbeddedCodeHandler(MarkupParsingContext context, String code)
at WebMarkupMin.Core.Parsers.HtmlParser.ProcessEmbeddedCode()
at WebMarkupMin.Core.Parsers.HtmlParser.Parse(String content)
at WebMarkupMin.Core.GenericHtmlMinifier.Minify(String content, String fileContext, Encoding encoding, Boolean generateStatistics)
at WebMarkupMin.Core.HtmlMinifier.Minify(String content, String fileContext, Encoding encoding, Boolean generateStatistics)
at WebMarkupMin.AspNetCore8.BodyWrapperStreamBase.<InternalFinishAsync>d__24.MoveNext()
at WebMarkupMin.AspNetCore8.BodyWrapperStreamWithResponseBodyFeature.<FinishAsync>d__5.MoveNext()
at WebMarkupMin.AspNetCore8.WebMarkupMinMiddleware.<InvokeCore>d__2.MoveNext()
at WebMarkupMin.AspNetCore8.WebMarkupMinMiddleware.<InvokeCore>d__2.MoveNext()
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__5.MoveNext()
at Microsoft.AspNetCore.Session.SessionMiddleware.<Invoke>d__8.MoveNext()
at Microsoft.AspNetCore.Session.SessionMiddleware.<Invoke>d__8.MoveNext()
at Nop.Services.Installation.InstallUrlMiddleware.<InvokeAsync>d__2.MoveNext() in C:\Users\test01\Desktop\Source\nopCommerce\src\Libraries\Nop.Services\Installation\InstallUrlMiddleware.cs:line 50
Regression?
Yes
Verify Scenarios: 1). Windows 10 21H2 AMD64 + default target net8.0 + default dotnet-sdk-8.0.300: Pass 2). Windows 10 21H2 AMD64 + default target net8.0 + dotnet-sdk-9.0.100-preview.7.24379.15: Pass 3). Windows 10 21H2 AMD64 + target net9.0 + dotnet-sdk-9.0.100-preview.5.24307.3: Pass 4). Windows 10 21H2 AMD64 + target net9.0 + dotnet-sdk-9.0.100-preview.6.24328.19: Fail 5). Windows 10 21H2 AMD64 + target net9.0 + dotnet-sdk-9.0.100-preview.7.24375.12: Fail 6). Windows 10 21H2 AMD64 + target net9.0 + dotnet-sdk-9.0.100-preview.7.24379.15: Fail
Known Workarounds
No response
Configuration
Application Name: nopCommerceNetCore OS:Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.7.24379.15 App Source or Repro machine checking at : https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2187455 GitHub Link: https://github.com/nopSolutions/nopCommerce
Dotnet Info:
.NET SDK:
Version: 9.0.100-preview.7.24379.15
Commit: 812e813ae9
Workload version: 9.0.100-manifests.28aae763
MSBuild version: 17.12.0-preview-24374-02+48e81c6f1
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-preview.7.24379.15\
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.
Host:
Version: 9.0.0-preview.7.24376.15
Architecture: x64
Commit: static
.NET SDKs installed:
3.0.103 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]
8.0.400-preview.0.24324.5 [C:\Program Files\dotnet\sdk]
9.0.100-preview.7.24379.15 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0-preview.7.24379.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0-preview.7.24376.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0-preview.7.24379.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other information
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 52 (49 by maintainers)
Per @javiercn: seems like it is likely an instance of https://github.com/dotnet/aspnetcore/issues/57138 which was fixed recently by https://github.com/dotnet/aspnetcore/pull/57170
That seems to be the next piece of the puzzle, there is no “type” attribute in the .NET 9 run, so the code above adds an attribute
type="text/javascript"and things go downhill from there.Suggests perhaps it is an issue in …? Razor? Not sure.
I am hoping @javiercn can look once more now that we know what version of nop Commerce to use. If that’s not possible I can look later this week, but it’s likely outside my area of expertise.
@Junjun-zhao can you confirm that this app still passes with Preview 5? I’m concerned this investigation is getting side-tracked on the specifics of the crash and missing the behavior difference.
@sebastienros This is an app-compat failure. The app is reported to work on Preview 5 and fails starting with Preview 6. It’s totally possible that something external to the app changed, which is why I asked Junjun to double-check the status of preview 5. But, any bug in the library is irrelevant WRT the behavioral regression (assuming it still shows as a regression). We may decide that whatever change in behavior is by design, but we can’t do that until we know what that behavior is.