-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
Unhandled exception. System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length') #1604
Comments
@zwluoqi Thanks for reporting this. We would however need a reproducable example to even know how to fix this and to make sure it doesn't happen again. |
looking at the source code the posted stack trace, it seems the issue is occurring in Which then poses the question as to why the Ergo, reproducing the problem requires a Based on this, i made some quick'n'dirty reproduction code (which i wrote and tested using Spectre.Console 0.49.2-preview.0.16): using Spectre.Console;
using System.Text;
Console.OutputEncoding = Encoding.UTF8;
int stringWidth = 20;
var table = new Table() { Width = 50 };
table.AddColumn("Foo");
table.AddColumn("Bar");
//
// Adding paragraphs with strings mainly composed of single-cell characters is fine...
//
table.AddRow(
new Paragraph(new string('a', stringWidth)) { Overflow = Overflow.Ellipsis },
new Paragraph(new string('b', stringWidth)) { Overflow = Overflow.Ellipsis }
);
AnsiConsole.Write(table);
//
// Exception happens here when adding the paragraphs with the CJK strings to the table
//
table.AddRow(
new Paragraph(new string('한', stringWidth)) { Overflow = Overflow.Ellipsis },
new Paragraph(new string('글', stringWidth)) { Overflow = Overflow.Ellipsis }
);
//
// Using Overflow.Crop would get the same kind of exception
//
// table.AddRow(
// new Paragraph(new string('한', stringWidth)) { Overflow = Overflow.Crop },
// new Paragraph(new string('글', stringWidth)) { Overflow = Overflow.Crop }
// );
AnsiConsole.Write(table); (dotnetfiddle: https://dotnetfiddle.net/HREpNo) |
Information
Describe the bug
To Reproduce
Expected behavior
Unhandled exception. System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
at System.String.ThrowSubstringArgumentOutOfRange(Int32, Int32)
at System.String.Substring(Int32, Int32)
at Spectre.Console.Rendering.Segment.SplitOverflow(Segment, Nullable
1, Int32) in /_/src/Spectre.Console/Rendering/Segment.cs:line 371 at Spectre.Console.Paragraph.SplitLines(Int32) in /_/src/Spectre.Console/Widgets/Paragraph.cs:line 232 at Spectre.Console.Paragraph.Render(RenderOptions, Int32) in /_/src/Spectre.Console/Widgets/Paragraph.cs:line 141 at Spectre.Console.TableRenderer.Render(TableRendererContext, List
1) in //src/Spectre.Console/Widgets/Table/TableRenderer.cs:line 11at Spectre.Console.TableRenderer.Render(TableRendererContext, List
1) in /_/src/Spectre.Console/Widgets/Table/TableRenderer.cs:line 31 at Spectre.Console.Padder.Render(RenderOptions, Int32) in /_/src/Spectre.Console/Widgets/Padder.cs:line 45 at Spectre.Console.Rendering.LiveRenderable.Render(RenderOptions, Int32)+MoveNext() at System.Collections.Generic.List
1.AddRange(IEnumerable1) at Spectre.Console.RenderableExtensions.GetSegments(IAnsiConsole, RenderOptions, IEnumerable
1) in //src/Spectre.Console/Extensions/RenderableExtensions.cs:line 34at Spectre.Console.AnsiBuilder.Build(IAnsiConsole, IRenderable) in //src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs:line 17
at Spectre.Console.AnsiConsoleFacade.Write(IRenderable) in //src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs:line 38
at Spectre.Console.ProgressRefreshThread.Run() in /_/src/Spectre.Console/Live/Progress/ProgressRefreshThread.cs:line 45
at System.Threading.Thread.StartCallback()
Screenshots
Additional context
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: