Crash if press enter key after changing line and caret postiion to end of document

SyntaxEditor for WPF Forum

Posted 8 years ago by Mark
Version: 16.1.0633
Platform: .NET 4.5
Environment: Windows 10 (64-bit)

Is there a fix or a workaround for this issue?

  1. Run test app
  2. Click the "Open" button to load a file
  3. Enter a number in the "Jump" text box which is higher than the total number of lines in the loaded file.
  4. Click the "Jump" button.
  5. Press enter
  6. Unhandled exception is thrown "ArgumentOutOfRangeException"

To reproduce this issue, please use the following code to create a simple test app:

<Window x:Class="WpfApplication2.MainWindow"
        Title="MainWindow" Height="350" Width="525">
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        <syntaxeditor:SyntaxEditor Name="actiproEditor" IsLineNumberMarginVisible="True" IsOutliningMarginVisible="False" IsSelectionMarginVisible="False"
                FontFamily="Consolas" FontSize="16" TextOptions.TextFormattingMode="Display" IsDefaultContextMenuEnabled="False"
                Background="White" LineNumberMarginForeground="Gray" IsCurrentLineHighlightingEnabled="True">

        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Content="Open" Margin="0,0,5,0" Click="Open_OnClick"/>
            <Button Content="Jump" Margin="5,0" Click="Jump_OnClick"/>
            <TextBox Name="txtJump" Text="100"  Margin="5,0"/>


using System.Windows;

namespace WpfApplication2
    using Microsoft.Win32;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
        public MainWindow()

        private void Open_OnClick(object sender, RoutedEventArgs e)
            var dialog = new OpenFileDialog();
            var result = dialog.ShowDialog();

            if (result.Value)

        private void Jump_OnClick(object sender, RoutedEventArgs e)
            var line = (int)double.Parse(this.txtJump.Text);
            line = line - 1; // in Actipro Synax Editor the first line is line #0
            if (line < 0)
                line = 0;
            else if (line >= this.actiproEditor.ActiveView.CurrentSnapshot.Lines.Count)
                line = this.actiproEditor.ActiveView.CurrentSnapshot.Lines.Count;

            var position = new ActiproSoftware.Text.TextPosition(line, 0);
            this.actiproEditor.ActiveView.Scroller.ScrollIntoView(position, false);
            this.actiproEditor.Caret.Position = position;

Comments (1)

Answer - Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Mark,

I think the problem is your line 38 where you are recognizing a line is out of range but you forgot to subtract 1 in response.  A better way to do all that would simply be this at line 31, as it will do proper bounds checking:

var lineIndex = Math.Max(0, Math.Min(actiproEditor.ActiveView.CurrentSnapshot.Lines.Count - 1, line - 1));  // Line indices are zero-based

Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.