Error on calling ProcessSegmentPairs

Hi,

I'm trying the manipulate segments with ProcessSegmentPairs, but I always get the following exception in Studio 2015 12.0.4996.3:

System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
at Sdl.TranslationStudio.Editor.AbstractActiveRangeAction.IsActionEnabled()
at Sdl.TranslationStudio.Api.Editor.AbstractActiveDocumentAction.UpdateAction()
at Sdl.TranslationStudio.Editor.AbstractActiveRangeAction.sideBySideEditor_Target_Entered(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnGotFocus(EventArgs e)
at System.Windows.Forms.Control.WmSetFocus(Message& m)
at System.Windows.Forms.Control.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)

And then immediately another one:

System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

at Sdl.TranslationStudioAutomation.IntegrationApi.Document.ProcessSegment(String processingName, ISegmentContainerNode segmentContainerNode, Action`2 process)
at Sdl.TranslationStudioAutomation.IntegrationApi.Document.ProcessSegmentPairs(String processingName, Action`2 process)
at Kaleidoscope.SmartQuery.Plugin.Utility.SmartQueryDataHandlerV2.SavePostedQueryInformation(Int32 queryId)

This is all I try to do at the moment:

if (editorController != null && editorController.ActiveDocument != null)
editorController.ActiveDocument.ProcessSegmentPairs(SmartDataTagOperationName, (pair, args) =>
{
});

The strange is that the same works in Studio2014. Can you please help?

thanks,

Tamas

Parents
  • Studio 2015 CU5 was launched today and includes the fix for this issue.

    Romulus Crisan | Translation Productivity Development Manager | SDL | (twitter) @cromica_82 | (blog) http://www.romuluscrisan.com/

  • Hi,

    I have v 12.2.5099.5, but I can still reproduce the error, same error messages.
    The only difference is that now it is not enough to simply iterate through the segments. Now I also try to change the meta data of a segment:

    editorController.ActiveDocument.ProcessSegmentPairs(SmartDataTagOperationName, (pair, args) =>
    {
    if (id.Equals(pair.Properties.Id))
    {
    pair.Source.Properties.TranslationOrigin.SetMetaData(SmartDataTag, metaData);
    }
    });

    The result are the two error messages cited in the first post.

    Thanks,
    Tamas
  • Hello,

    as the ProcessSegmentPairs is now working for me I would like to share my experience.

     
    Immediately after installing 12.2.5099.5 I also continued to have a NullReferenceException. However, it was not caused by the ProcessSegmentPairs method but by the UpdateSegmentPair method which seems to be called automatically by ProcessSegmentPairs. In another post it was mentioned that it was necessary to set the active segment pair before calling UpdateSegmentPair. Therefore I added the following line before the code which is dealing with the segment content:

    [Reference to ActiveDocument].SetActiveSegmentPair(pair.GetProjectFile(), pair.Properties.Id.Id);

    Try to set the active segment pair in your if statement.

    Hope this helps.

    Thomas

  • Hi Thomas and Tamás,

    We are aware of remaining null reference exceptions when using the integration API and are preparing a hotfix for the next CU (to be released in a few weeks time from what I can say today). The below is preliminary info on the nature of the fix:

    "The following API methods have been marked as deprecated. A warning will be given to the developers if they continue to use them but it will not break their plugin build. We have changed the method implementation to prevent null reference exceptions being thrown. For virtually merged documents in the editor, the first segment in the merged document with the matching segment ID will be used.
    GetCommentsFromSegment(string segmentId)
    AddCommentOnSegment(string segmentId, string text, Severity severity)
    UpdateCommentOnSegment(string segmentId, IComment commentToUpdate, string text, Severity severity)
    DeleteCommentOnSegment(string segmentId, IComment commentToDelete)
    DeleteAllCommentsOnSegment(string segmentId)
    ChangeConfirmationLevelOnSegment(string segmentId, ConfirmationLevel newConfirmationLevel)
    ChangeTranslationOriginOnSegment(string segmentId, string originType)
    ProcessSegmentPair(string segmentId, string processingName, Action<ISegmentPair, CancelEventArgs> process)
    UpdateSegmentPairProperties(ISegmentPairProperties segmentPairProperties)

    The following API methods (with the same functionality as those listed above) have been added with an ISegmentPair parameter to identify the segment to be used:
    GetCommentsFromSegment(ISegmentPair segmentPair)
    AddCommentOnSegment(ISegmentPair segmentPair, string text, Severity severity)
    UpdateCommentOnSegment(ISegmentPair segmentPair, IComment commentToUpdate, string text, Severity severity)
    DeleteCommentOnSegment(ISegmentPair segmentPair, IComment commentToDelete)
    DeleteAllCommentsOnSegment(ISegmentPair segmentPair)
    ChangeConfirmationLevelOnSegment(ISegmentPair segmentPair, ConfirmationLevel newConfirmationLevel)
    ChangeTranslationOriginOnSegment(ISegmentPair segmentPair, string originType)
    ProcessSegmentPair(ISegmentPair segmentPair, string processingName, Action<ISegmentPair, CancelEventArgs> process)
    UpdateSegmentPairProperties(ISegmentPair segmentPair, ISegmentPairProperties segmentPairProperties)
    Additionally, the implementation of UpdateSegmentPair has been enhanced to remove the use of ActiveSegmentPair."

    Thanks
    Daniel

    Daniel Brockmann
    Team Trados @ RWS

Reply
  • Hi Thomas and Tamás,

    We are aware of remaining null reference exceptions when using the integration API and are preparing a hotfix for the next CU (to be released in a few weeks time from what I can say today). The below is preliminary info on the nature of the fix:

    "The following API methods have been marked as deprecated. A warning will be given to the developers if they continue to use them but it will not break their plugin build. We have changed the method implementation to prevent null reference exceptions being thrown. For virtually merged documents in the editor, the first segment in the merged document with the matching segment ID will be used.
    GetCommentsFromSegment(string segmentId)
    AddCommentOnSegment(string segmentId, string text, Severity severity)
    UpdateCommentOnSegment(string segmentId, IComment commentToUpdate, string text, Severity severity)
    DeleteCommentOnSegment(string segmentId, IComment commentToDelete)
    DeleteAllCommentsOnSegment(string segmentId)
    ChangeConfirmationLevelOnSegment(string segmentId, ConfirmationLevel newConfirmationLevel)
    ChangeTranslationOriginOnSegment(string segmentId, string originType)
    ProcessSegmentPair(string segmentId, string processingName, Action<ISegmentPair, CancelEventArgs> process)
    UpdateSegmentPairProperties(ISegmentPairProperties segmentPairProperties)

    The following API methods (with the same functionality as those listed above) have been added with an ISegmentPair parameter to identify the segment to be used:
    GetCommentsFromSegment(ISegmentPair segmentPair)
    AddCommentOnSegment(ISegmentPair segmentPair, string text, Severity severity)
    UpdateCommentOnSegment(ISegmentPair segmentPair, IComment commentToUpdate, string text, Severity severity)
    DeleteCommentOnSegment(ISegmentPair segmentPair, IComment commentToDelete)
    DeleteAllCommentsOnSegment(ISegmentPair segmentPair)
    ChangeConfirmationLevelOnSegment(ISegmentPair segmentPair, ConfirmationLevel newConfirmationLevel)
    ChangeTranslationOriginOnSegment(ISegmentPair segmentPair, string originType)
    ProcessSegmentPair(ISegmentPair segmentPair, string processingName, Action<ISegmentPair, CancelEventArgs> process)
    UpdateSegmentPairProperties(ISegmentPair segmentPair, ISegmentPairProperties segmentPairProperties)
    Additionally, the implementation of UpdateSegmentPair has been enhanced to remove the use of ActiveSegmentPair."

    Thanks
    Daniel

    Daniel Brockmann
    Team Trados @ RWS

Children
No Data