Hi DevExpress
I have a project where I wish to inspect the contents of the selected text in the XtraRichEdit control.
Within the SelectionChanged event I get the selected text of a .docx document by calling the following
C#var sel = richEditControl1.Document.Selection;
var selectedText = richEditControl1.Document.GetText(sel);
If the user then selects a large amount of text by clicking, holding left mouse button and dragging down (or using the mouse wheel) over multiple pages we get the exception below. I created a simple project and can reproduce each time with a .docx document.
C#An unhandled exception of type 'System.NullReferenceException' occurred in DevExpress.XtraRichEdit.v15.1.dll
Additional information: Object reference not set to an instance of an object.
at DevExpress.XtraRichEdit.Commands.Internal.ExtendSelectionByRangesCommandBase.set_InitialBox(Box value)
at DevExpress.XtraRichEdit.Mouse.ContinueSelectionByRangesMouseHandlerState.ContinueSelection(MouseEventArgs e)
at DevExpress.XtraRichEdit.Mouse.ContinueSelectionByCharactersMouseHandlerState.ContinueSelection(MouseEventArgs e)
at DevExpress.XtraRichEdit.Mouse.ContinueSelectionByRangesMouseHandlerState.OnMouseWheel(MouseEventArgs e)
at DevExpress.XtraRichEdit.Mouse.RichEditMouseHandler.HandleMouseWheel(MouseEventArgs e)
at DevExpress.Utils.MouseHandler.OnMouseWheel(MouseEventArgs e)
at DevExpress.Services.Implementation.MouseHandlerService.OnMouseWheel(MouseEventArgs e)
at DevExpress.XtraRichEdit.Internal.InnerRichEditControl.OnMouseWheel(MouseEventArgs e)
at DevExpress.XtraRichEdit.RichEditControl.OnMouseWheelCore(MouseEventArgs e)
at DevExpress.XtraRichEdit.RichEditControl.OnMouseWheel(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseWheel(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.XtraRichEdit.RichEditControl.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(IntPtr 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(Form mainForm)
at WindowsFormsApplication3.Program.Main() in c:\users\....\documents\visual studio 2015\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Hello James,
I noticed that the same call stack was already specified in the NullReferenceException is thrown while selecting document text before images located in this document are loaded thread, but the problem described in that thread was already fixed in version 15.1.3. Is this exception also reproduced in version 15.1.6? If so, please provide us with the project to reproduce the behavior on our side.
If you use the older version, I recommend you upgrade the project to the latest minor version to fix the behavior on your side.
I'm looking forward to your response.
Hi Mariya,
yes i'm using DevExpress.XtraRichEdit.v15.1 version 15.1.6.0
public Form1()
{
InitializeComponent();
richEditControl1.LoadDocument(@"C:\New Microsoft Word Document.docx");
richEditControl1.SelectionChanged += RichEditControl1_SelectionChanged;
}
private void RichEditControl1_SelectionChanged(object sender, EventArgs e)
{
var sel = richEditControl1.Document.Selection;
var selectedText = richEditControl1.Document.GetText(sel);
}
It seems that the issue relates to the document specific. Would you please provide me with the document specified in your code? Note that you can mark this ticket as private if required…
Nope, not document specific. Have repeated with many documents (make sure you have quite a few pages)
Actually, I have managed to repeat with .RTF documents as well
Well, the exception can occur with this code if you click the TextBox since the TextBox range relates to a different SubDocument in this case. To avoid this exception, you can use the following condition:
var sel = richEditControl1.Document.Selection; SubDocument subDocument = sel.BeginUpdateDocument(); if (subDocument is Document) { sel.EndUpdateDocument(subDocument); var selectedText = richEditControl1.Document.GetText(sel); }
However, the call stack of this exception is different than the call stack you specified previously, and I was not able to reproduce your exception on my side. I've attached a video illustrating the behavior in my case.
So, I'd like to ask you to provide us with the project, document or a video illustrating how to reproduce it. Perhaps, it's possible to reproduce this exception with the document used in our Demo.
I'm looking forward to your clarification.
Thank you for the sample. I reproduced this behavior and passed the issue to our R&D team for further research.
Please watch for our updates. We will notify you as soon as we make any progress.