Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When running 3rd part application with the latest .NET 9 build, BlazorStrap and Blog apps failed load page content during switching pages in applications. And the command prompt window throws "The parser is in an invalid infinite loop while trying to parse inlines for block [ParagraphBlock] at position ($0, 0, 0-107" exception
.
Application Name: BlazorStrap, Blog, OpenBullet2
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-9.0.100-preview.7.24375.12
App or App Source checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2174456
Github Link:
https://github.com/chanan/BlazorStrap
https://github.com/sagebind/blog
Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.303: Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24371.4: Pass
3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24375.12: Fail
Expected Behavior
Switch back from "Shared Parameters" to "Contribute" successfully.
Steps To Reproduce
The machine has dotnet-sdk-9.0.100-preview.7.24375.12 installed.
- Copy BlazorStrap app from the location mentioned in the devdiv bug.
- Change the "BlazorStrap.Server.runtimeconfig.json" file to let the app run against with dotnet-sdk-dotnet-sdk-9.0.100-preview.7.24375.12.
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0-preview.7.24374.12"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "9.0.0-preview.7.24373.9"
}
], - Launch BlazorStrap.Server.exe.
- Access http://localhost:5000/ from browser.
- Click "Contribute" menu.
- Click "Shared Parameters" menu.
- Click "Contribute" menu.
Exceptions (if any)
Actual Result:
Switch back from "Shared Parameters" to "Contribute" failed.
Stack Trace from Command Prompt:
Unhandled exception rendering component: The parser is in an invalid infinite loop while trying to parse inlines for block [HeadingBlock] at position ($0, 0, 0-19
System.InvalidOperationException: The parser is in an invalid infinite loop while trying to parse inlines for block [HeadingBlock] at position ($0, 0, 0-19
at Markdig.Helpers.ThrowHelper.InvalidOperationException(String message)
at Markdig.Parsers.InlineProcessor.ProcessInlineLeaf(LeafBlock leafBlock)
at Markdig.Parsers.MarkdownParser.ProcessInlines(InlineProcessor inlineProcessor, MarkdownDocument document)
at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context)
at BlazorStrap_Docs.Helper.MarkdownToComponent.BuildRenderTree(RenderTreeBuilder builder) in C:\Users\v-zhiyang\Desktop\YOURSELF\BlazorStrap\src\BlazorStrap-Docs\Helper\MarkdownToComponent.cs:line 93
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'cwy0vMhNv_dIuMXmt46dyA7Bj5ivmQY-xXaGYDTlK6s'.
System.InvalidOperationException: The parser is in an invalid infinite loop while trying to parse inlines for block [HeadingBlock] at position ($0, 0, 0-19
at Markdig.Helpers.ThrowHelper.InvalidOperationException(String message)
at Markdig.Parsers.InlineProcessor.ProcessInlineLeaf(LeafBlock leafBlock)
at Markdig.Parsers.MarkdownParser.ProcessInlines(InlineProcessor inlineProcessor, MarkdownDocument document)
at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context)
at BlazorStrap_Docs.Helper.MarkdownToComponent.BuildRenderTree(RenderTreeBuilder builder) in C:\Users\v-zhiyang\Desktop\YOURSELF\BlazorStrap\src\BlazorStrap-Docs\Helper\MarkdownToComponent.cs:line 93
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
.NET Version
9.0.100-preview.7.24375.12
Anything else?
Minimal Repro steps (repro demo attached
MarkdownToHtmlDemo.zip):
1.Create a Blazor Server App project.
2. Install Markdig nuget package.
3. Add a MarkdownToComponent.cs class file with following content:
public class MarkdownToComponent : ComponentBase
{
[Parameter] public RenderFragment? ChildContent { get; set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
string s = @"The following are **guide lines** on howto contribute. You input is always **welcomed** and **appreciated**.
### Feature Request
---
If you feel BlazorStrap is lacking a feature you need or just want please create a issue with the following.
* What does it do
* Why you feel it should exist
* How can it help others";
string ms = Markdown.ToHtml(s);
}
}
- Add above component to Counter.razor page.
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<MarkdownToComponent>Test</MarkdownToComponent>
- Build the project.
- Update the runtime.config file to run against with dotnet-sdk-dotnet-sdk-9.0.100-preview.7.24375.12.
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0-preview.7.24374.12"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "9.0.0-preview.7.24373.9"
}
],
- Launch the project.
- Access http://localhost:5000/ from browser.
- Navigate to Counter page.
- Refresh the Counter page 7 times.
Expected Result:
The Counter page refresh 7 time successfully.
Actual Result:
The Counter page refresh failed at the 7th refresh with following error:
System.InvalidOperationException: 'The parser is in an invalid infinite loop while trying to parse inlines for block [ParagraphBlock] at position ($0, 0, 0-107'
Stack Trace:
at Markdig.Helpers.ThrowHelper.InvalidOperationException(String message)
at Markdig.Parsers.InlineProcessor.ProcessInlineLeaf(LeafBlock leafBlock)
at Markdig.Parsers.MarkdownParser.ProcessInlines(InlineProcessor inlineProcessor, MarkdownDocument document)
at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
at Markdig.Markdown.ToHtml(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context)
at MarkdownToHtmlDemo.MarkdownToComponent.BuildRenderTree(RenderTreeBuilder builder) in E:\Demos\MarkdownToHtmlDemo\MarkdownToHtmlDemo\MarkdownToComponent.cs:line 26
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
Findings:
- 2 apps are all referenced Markdig nuget package and the exception in 2 apps are both thrown from Markdown.ToHtml() method which is used to convert a markdown file sting to html.
- We tried to reference the Markdig (version 0.37.0) source code instead of install it from nuget package manager, it doesn't repro in debug mode. But if we enable compiler optimizations on debug mode for Markdig project, this issue will repro again. It doesn't have this issue on build#dotnet-sdk-9.0.100-preview.7.24371.4 . We think something changed with optimization code in 9.0.100-preview.7.24375.12 which cause this issue.
- The Markdig nuget package is used by 5.8k users. It may affect more users in real world.
- This issue will occurs after switching pages in applications multiple times or refresh the page multiple times. The first time load the page can successful.
@dotnet-actwx-bot @dotnet/compat