That's not a compiler error, that's a runtime error.
Note the documentation for String.Substring(int, int):
Retrieves a substring from this instance. The substring starts at a specified character position [startIndex] and has a specified length [length].
So the substring will have the specified length. Therefore, there must be enough characters starting at startIndex to return a substring of the specified length. Therefore, the following inequalities must be satisfied for String.Substring to succeed on an instance s of string:
startIndex >= 0
length >= 0
length > 0 implies startIndex + length <= s.Length
Note that if you just want a substring from index to the end of the string, you can say
s.Substring(index);
Here, the only constraint is
startIndex>= 0
startIndex < s.Length