Issue in Generating TOC

Hello,
I am using below code to Update TOC.

Aspose.Words.Document.UpdateFields();
Aspose.Words.Document.UpdatePageLayout();

But it throwing below exception.

System.NullReferenceException: Object reference not set to an instance of an object.     at   .    (   , Boolean )     at   .​   (​  )     at   .(   )     at   .​   (​  )     at ​ .​   (​  , ​  , ​  , Boolean )     at   .(​  )     at   .​   (​  )     at   .(   , ​  , ​  )     at   .(   , ​  , ​  )     at   .(   , ​  , ​  )     at   .(​  )     at   .()     at   .()     at   .(Field ,    , Boolean )     at   .    (Field , Boolean )     at    .(    )     at    . (    )     at    .(    )     at    .(    ,     )     at    .(Node ,     )     at Aspose.Words.Document.UpdateFields()  .

And TOC not generated.

Can you suggest to avoid this exception and generate TOC.

@RiteshK10 Could you please attach your input document here for testing? We will check the issue and provide you more information.