IndexOutOfRange Exception

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Rick - Developer, Visual Software Systems LLC
Version: 4.0.0249
Platform: .NET 2.0
Environment: Windows XP (32-bit)
Avatar
I'm receiving a really strange IndexOutOfRange exception from SyntaxEditor while handling the DocumentModifiedChanged event on the initial change to a document. My project uses SE, DockManager, and BarManager, with DocumentWindows displayed in TabbedMDI mode. There's a SyntaxEditor control within the DocumentWindow. As far as I can determine, the problem is dependent upon the number of invisible lines in the editor. I have only experienced it when a single line is not within the visible area of the editor and there's only one DocumentWindow open. If I have more than one document window open, I do not receive the error. If I resize the DocumentWindow before modifying it, I do not receive the error. If I change the font size or turn off line numbers, I do not receive the error.

Here's the event code. It throws the error on the '.Text &= "*"' line and "Me" is the DocumentWindow:
    Private Sub SyntaxEditor1_DocumentModifiedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SyntaxEditor1.DocumentModifiedChanged

        With Me
            If SyntaxEditor1.Document.Modified Then
                .Text &= "*"
            Else
                .Text = .Key
            End If
            .TitleBarText = .Text
        End With


    End Sub
Here's the exception information:
System.IndexOutOfRangeException was unhandled
  Message="Index was outside the bounds of the array."
  Source="ActiproSoftware.SyntaxEditor.Net20"
  StackTrace:
       at be.b(Int32 A_0)
       at bk.a(Int32 A_0)
       at ActiproSoftware.SyntaxEditor.DisplayLineCollection.e(Int32 A_0)
       at ActiproSoftware.SyntaxEditor.EditorView.a(Boolean A_0, Boolean A_1)
       at ActiproSoftware.SyntaxEditor.EditorView.ArrangeCore()
       at ActiproSoftware.WinUICore.UIElement.Arrange(Rectangle newBounds)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.ArrangeCore()
       at ActiproSoftware.WinUICore.UIControl.Arrange(Rectangle newBounds)
       at ActiproSoftware.WinUICore.UIControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.WinUICore.UIControl.OnLayout(LayoutEventArgs e)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at ActiproSoftware.WinUICore.UIContainerControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIContainerControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.WinUICore.UIContainerControl.OnLayout(LayoutEventArgs e)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at ActiproSoftware.WinUICore.UIControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.WinUICore.UIControl.OnLayout(LayoutEventArgs e)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at ActiproSoftware.WinUICore.UIContainerControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIContainerControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.WinUICore.UIContainerControl.OnLayout(LayoutEventArgs e)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at ActiproSoftware.WinUICore.UIContainerControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIContainerControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.WinUICore.UIContainerControl.OnLayout(LayoutEventArgs e)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at ActiproSoftware.WinUICore.UIControl.UpdateLayout()
       at ActiproSoftware.WinUICore.UIControl.Invalidate(InvalidationLevels levels, InvalidationTypes types)
       at ActiproSoftware.UIStudio.TabStrip.TabStripPage.set_Text(String value)
       at ActiproSoftware.UIStudio.Dock.TabbedMdiContainer.d()
       at ActiproSoftware.UIStudio.Dock.TabbedMdiWindow.UpdateUI()
       at ActiproSoftware.UIStudio.Dock.TabbedMdiWindow.set_Text(String value)
       at WindowsApp.Editor.SyntaxEditor1_DocumentModifiedChanged(Object sender, EventArgs e) in P:\Visual Studio .NET 2005\WindowsApplication1\WindowsApplication1\ToolWindows\Editor.vb:line 1057
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.OnDocumentModifiedChanged(EventArgs e)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.n(Object A_0, EventArgs A_1)
       at ActiproSoftware.SyntaxEditor.Document.OnModifiedChanged(EventArgs e)
       at ActiproSoftware.SyntaxEditor.Document.set_Modified(Boolean value)
       at ActiproSoftware.SyntaxEditor.UndoRedo.b(DocumentModificationEventArgs A_0)
       at ActiproSoftware.SyntaxEditor.Document.a(DocumentModification A_0, Boolean A_1)
       at ActiproSoftware.SyntaxEditor.Document.b(DocumentModificationType A_0, Int32 A_1, Int32 A_2, String A_3, DocumentModificationOptions A_4, WeakReference A_5)
       at ActiproSoftware.SyntaxEditor.Document.a(DocumentModificationType A_0, Int32 A_1, Int32 A_2, String A_3, DocumentModificationOptions A_4, WeakReference A_5)
       at ActiproSoftware.SyntaxEditor.EditorView.a(DocumentModificationType A_0, String A_1, DocumentModificationOptions A_2)
       at ActiproSoftware.SyntaxEditor.EditorView.ReplaceSelectedText(DocumentModificationType type, String text, DocumentModificationOptions options)
       at ActiproSoftware.SyntaxEditor.Commands.TypingCommand.Execute(EditCommandContext context)
       at ActiproSoftware.SyntaxEditor.MacroRecording.a(EditCommand A_0, EditCommandContext A_1)
       at ActiproSoftware.SyntaxEditor.EditorView.a(EditCommand A_0, Boolean A_1)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.a(EditorView A_0, Keys A_1, Char A_2, Boolean A_3)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.OnKeyPress(KeyPressEventArgs e)
       at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
       at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
       at System.Windows.Forms.Control.WmKeyChar(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at WindowsApp.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
I hope you can help. I've been pulling my hair out for most of the day over this one. I have tried to reproduce the exception in the SE sample project and from another small project, but have not been successful.


Thanks,
Rick

Comments (5)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Rick,

There's a lot happening there so it's really hard to say what it could be unless we could debug a sample project that shows it. I'd really appreciate it if you could continue trying to dupe it in a small sample that you could send us.

As a temporary workaround, what if in your event handler, you surround the code with Me.SuspendLayout and as the last line Me.ResumeLayout? That might prevent the exception from happening until we can get a repro of this which we can debug.


Actipro Software Support

Posted 12 years ago by Rick - Developer, Visual Software Systems LLC
Avatar
I'll try the SuspendLayout/ResumeLayout workaround and let you know if that works. I'll also continue to try to replicate the problem in a small project.

Thanks,
Rick
Posted 12 years ago by Rick - Developer, Visual Software Systems LLC
Avatar
I was able to recreate the problem in a small sample project. I emailed it to you.

Thanks,
Rick
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks Rick, debugged it and fixed it for the next maintenance release. Adding the * in your tool window kicked off a layout of the SyntaxEditor while it was still updating UI for the display lines. In my change, the ModifiedChanged event will fire after that UI is updated.


Actipro Software Support

Posted 12 years ago by Rick - Developer, Visual Software Systems LLC
Avatar
Awesome. Thanks!
The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.