System.ArgumentException: The text range '{StartOffset=5538,

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Jonathan Reis
Version: 4.0.0284
Platform: .NET 4.0
Environment: Windows XP (32-bit)
With the code below, I occassionally get the following exception.

Is there anything obvious that I'm doing wrong? Under what situation would a node returned by _syntaxEditor.Document.Outlining.RootNode[i] return a range that would be greater than the number of characters in the document?

Thanks in advance,


System.ArgumentException: The text range '{StartOffset=5538,EndOffset=12590}'
must be less than or equal to the count of characters in the document.
at ActiproSoftware.SyntaxEditor.TextRange.a(Document A_0)
at ActiproSoftware.SyntaxEditor.Document.GetSubstring(TextRange textRange, LineTerminator lineTerminator)
at ActiproSoftware.SyntaxEditor.Document.GetSubstring(Int32 offset, Int32 length)
at HL7Spy.Views.MessageQuery.HL7QueryView.(Object , EventArgs )
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
// find text within current region, or first region greater than current position
int offset = _syntaxEditor.Caret.Offset - _syntaxEditor.Caret.CharacterColumn;
for (int i = 0; i < _syntaxEditor.Document.Outlining.RootNode.Count; ++i)
    OutliningNode loc = _syntaxEditor.Document.Outlining.RootNode[i];
    if (i == 0 && offset < loc.StartOffset)
        string query = _syntaxEditor.Document.GetSubstring(offset, loc.StartOffset);
        if (query.Trim().Length > 0)
            sqlQuery = query;

    if (offset >= loc.StartOffset && offset < loc.EndOffset || loc.StartOffset > offset)
        sqlQuery = loc.Text;
[Modified at 05/15/2010 01:47 PM]

[Modified at 05/15/2010 01:56 PM]

Comments (2)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Jonathan,

GetSubstring takes offset/length, not start-offset/end-offset. That's your problem here.

Actipro Software Support

Posted 14 years ago by Jonathan Reis
Dough... Thanks very much for pointing that out to me!

The latest build of this product (v24.1.0) was released 4 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.