Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContainerBlock CopyTo IndexOutOfRangeException #628

Closed
ladeak opened this issue Apr 21, 2022 · 2 comments · Fixed by #630
Closed

ContainerBlock CopyTo IndexOutOfRangeException #628

ladeak opened this issue Apr 21, 2022 · 2 comments · Fixed by #630
Labels

Comments

@ladeak
Copy link

ladeak commented Apr 21, 2022

When I call ToList() on a ContainerBlock (ListItemBlock) with a single item in it, I get a IndexOutOfRangeException.

Stacktrace:

   at System.Runtime.CompilerServices.CastHelpers.StelemRef(Array array, Int32 index, Object obj)
   at Markdig.Syntax.ContainerBlock.CopyTo(Block[] array, Int32 arrayIndex)
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

This seems to be a regression since v28.1. I am still further looking into the detailts.

(.NET6, Blazor app)

@MihaZupan MihaZupan added the bug label Apr 21, 2022
@MihaZupan
Copy link
Collaborator

MihaZupan commented Apr 21, 2022

Caused by a typo here:

array[arrayIndex + 1] = children[i].Block;

Should be arrayIndex + i instead of arrayIndex + 1.

As a temporary workaround, you can avoid the CopyTo.

var list = new List<Block>(container.Count);
for (int i = 0; i < list.Count; i++)
    list[i] = container[i];

@ladeak
Copy link
Author

ladeak commented Apr 21, 2022

I was wondering why I did not find this piece of code... GitHub search has taken me to a different version of the file. 😡

It seems calling ToList() on MarkdownDocument results a weird list of, probably also caused by the same typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants