Both versions must reference the same ITextDocument??

SyntaxEditor for WPF Forum

Posted 9 years ago by Nate Smith - Software Engineer, Logical Progression Group
Version: 10.2.0532
Avatar
I have a couple of SyntaxEditors on two different tabs on a tabbed dialog, until I try to switch tabs all is well, but when I switch I get an exception I cannot make much sense of. Can anyone comment on what kind of thing could be wrong, or even how to debug further?

The exception pops up on the ShowDialog so it looks as if it is some code being called implicitly, rather than something my code does directly.

Here are the exception details, such as they are:

System.ArgumentException occurred
Message=Both versions must reference the same ITextDocument.
Source=ActiproSoftware.Text.Net351
StackTrace:
at ActiproSoftware.Text.TextRange.a(ITextVersion A_0, ITextVersion A_1, TextRangeTrackingModes A_2, Boolean A_3)
InnerException: null

Comments (6)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nate,

It's hard to say without seeing it occur, but that looks like it could be something deep in the internals. You should have no problems using multiple SyntaxEditors, and we haven't had this reported before.

Please make a new simple sample project that shows this issue and email it to us so that we can debug it. Reference this post in your email. Rename the .zip file extension so it doesn't get spam blocked and make sure to exclude any .exe files from within the ZIP. Thanks!


Actipro Software Support

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nate,

We just had another customer submit a similar issue with a sample, and it ended up being the collapsed region manager not handling document changes correctly and trying to translate the collapsed region range between snapshots of different documents. We've fixed it for the next maintenance release.


Actipro Software Support

Posted 3 months ago by K.C. Bell
Avatar

We're using Actipro v2016.1 in our application, and have seen this error out in the wild and reported back through our telemetry. Any sense if this is still a known issue, and/or if there is a known fix?

Here is the exception message/stack:

Both versions must reference the same ITextDocument.
   at ActiproSoftware.Text.TextRange.Translate(ITextVersion #bDf, ITextVersion #qCf, TextRangeTrackingModes #oCf, Boolean #cDf)
   at ActiproSoftware.Text.TextSnapshotRange.TranslateTo(ITextSnapshot toSnapshot, TextRangeTrackingModes trackingModes)

Here's our method that is calling ActiproSoftware code:

private static TextRange FindRangeInDestination(ITextSnapshot destination, TextSnapshotRange source)
{
    var translatedRange = source.TranslateTo(destination, TextRangeTrackingModes.Default).TextRange;
    if (!destination.TextRange.BordersOn(translatedRange))
    {
        return translatedRange;
    }
 
    return TextRange.Intersect(source, destination.TextRange);
}

The ITextSnapshot being sent as the destination parameter is

SyntaxEditor.ActiveView.CurrentSnapshot

[Modified 3 months ago]

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello, when you translate a text range between two snapshots, the snapshots must be from the same document.  Otherwise there is no way they can be translated since there is no history.  I would recommend adding a snapshot.Document equality check before ever translating between snapshots.

But you probably also want to sort out what scenario in your app is triggering the document to be changed.  Such as maybe you are swapping in a different document in the editor after caching the first snapshot?


Actipro Software Support

Posted 3 months ago by K.C. Bell
Avatar

Would you be able to point me towards any additional documentation you might have in this area, with these kinds of tips & tricks to watch out for?

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The "Snapshot Translation" topic in the documentation that comes with the product talks about the mechanism and various applicable scenario ideas at length.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.