Error on calling AddCommentOnSegment

Hi.

I am creating a plugin that is adding comments to segment of active sdlxliff file on Trados2017 using vs2017.

The following is my code.

At the calling AddCommentOnSegment line , the error "Object reference not set to an instance of an object" occurred, and the type is System.NullReferenceException.

I checked that doc, segPair,  strCMNT, and Data.DataInfo.SeverityType are not null.

I have no way to solve this error.

Can anyone give me some idea?


--------------Code-----------------------------------------------------------------------------------

public void VisitSegment(ISegment segment)
{          
    VisitChildren(segment);

    if (CMNTList.Count > 0)
    {
        SegmentId segId = segment.Properties.Id;

        IParagraphUnit paraUnit = segment.ParentParagraphUnit;
        ISegment TgtSeg = paraUnit.GetTargetSegment(segId);

        if ((TgtSeg != null) && (TgtSeg.Properties.IsLocked == false))
        {
            foreach (String strCMNT in CMNTList)
            {
                ISegmentPair segPair = paraUnit.GetSegmentPair(segId);
                //Doc.SetActiveSegmentPair(processDoc.ActiveFile, segPair.Properties.Id.Id);
                Doc.AddCommentOnSegment(segPair, strCMNT, (Severity)Data.DataInfo.SeverityType);   <---Error
            }
        }
    }
}



--------------Stack Trace -----------------------------------------------------------------------------------

at Sdl.TranslationStudioAutomation.IntegrationApi.Document.GetTargetSegmentContainerNode(ISegmentPair segmentPair)
at Sdl.TranslationStudioAutomation.IntegrationApi.Document.AddCommentOnSegment(ISegmentPair segmentPair, String text, Severity severity)
at IdeaTradosPlugin.TextExtractor.VisitSegment(ISegment segment)
at Sdl.FileTypeSupport.Framework.Bilingual.Segment.AcceptVisitor(IMarkupDataVisitor visitor)
at IdeaTradosPlugin.TextExtractor.VisitChildren(IEnumerable`1 container)
at IdeaTradosPlugin.TextExtractor.AddSegComment(IParagraph paragraph)
at IdeaTradosPlugin.TextExtractionBilingualContentHandler.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.Core.Utilities.BilingualApi.BilingualContentHandlerAdapter.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.Integration.AbstractBilingualProcessorContainer.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.BilingualApi.AbstractBilingualContentProcessor.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.Integration.LocationMarkerLocator.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.Integration.AbstractBilingualProcessorContainer.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.Integration.FileExtractor.ProcessParagraphUnit(IParagraphUnit paragraphUnit)
at Sdl.FileTypeSupport.Framework.Core.Utilities.BilingualApi.ParagraphUnitBuffer.ProcessParagraphUnit(IParagraphUnit pu)
at Sdl.FileTypeSupport.Bilingual.SdlXliff.XliffFileReader.OutputParagraphUnit(IParagraphUnit pu)
at Sdl.FileTypeSupport.Bilingual.SdlXliff.XliffFileReader.ParseLocalizableParagraphUnit(transunit transunit, LockTypeFlags lockFlags)
at Sdl.FileTypeSupport.Bilingual.SdlXliff.XliffFileReader.ParseTransUnit(transunit transunit)
at Sdl.FileTypeSupport.Bilingual.SdlXliff.XliffFileReader.OnTranslationUnit(XmlElement translationUnit)
at Sdl.FileTypeSupport.Bilingual.SdlXliff.SdlXliffFeeder.b__14_16(ISdlXliffStreamContentHandler handler)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Sdl.FileTypeSupport.Bilingual.SdlXliff.SdlXliffFeeder.ContinueScanning()
at Sdl.FileTypeSupport.Bilingual.SdlXliff.XliffFileReader.ContinueParsing()
at Sdl.FileTypeSupport.Bilingual.SdlXliff.XliffFileReader.ParseNext()
at Sdl.FileTypeSupport.Framework.Integration.FileExtractor.ParseNext()
at Sdl.FileTypeSupport.Framework.Integration.MultiFileConverter.ParseNext()
at Sdl.FileTypeSupport.Framework.Integration.MultiFileConverter.Parse()