IndexOutOfRange exception in StringExtensions.TrimFirstLine
See original GitHub issueSystem.IndexOutOfRangeException occurred
StackTrace:
at System.Text.StringBuilder.get_Chars(Int32 index)
at ExCSS.Model.Extensions.StringExtensions.TrimFirstLine(StringBuilder builder)
at ExCSS.StyleSheet.ToString(Boolean friendlyFormat, Int32 indentation)
at ExCSS.StyleSheet.ToString()
public static StringBuilder TrimFirstLine(this StringBuilder builder)
{
if (builder.Length > 0) // this check must be moved to "while"
{
while (builder[0] == '\r' || builder[0] == '\n' || builder[0] == '\t')
{
builder.Remove(0, 1);
}
}
return builder;
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
c# - What is an IndexOutOfRangeException ...
This exception means that you're trying to access a collection item by index, using an invalid index. An index is invalid when it's...
Read more >IndexOutOfRangeException Class (System)
The exception that is thrown when an attempt is made to access an element of an array or collection with an index that...
Read more >IndexOutOfRangeException in C#
It occurs when an invalid index is used to access a member of a collection. The following example throws the IndexOutOfRange exception: Example:....
Read more >IndexOutOfRangeException - ERP 10
Hi all, I'm new to Epicor, and we've recently been having a few issues. Lately, a service that we wrote that retrieves and...
Read more >C# IndexOutOfRangeException
This C# exception will typically occur when a statement tries to access an element at an index greater than the maximum allowable index....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Well, I was testing different inputs and it was failing like that on latest released version on empty string (string.Empty). On current code base it doesn’t fail due to some other changes since last release, so I have no inputs to reproduce it now using parser. But you still can reproduce it using isolated test for this extension method (and TrimLastLine):
Looking into it.