I have some code that looks roughly like this:
- Code: Select all
public void MacroBlockReplacementHelper(Spire.Doc.Document doc, CorrespondenceType.CorrespondenceTypes corrType, string macro)
{
IList<DocumentObject> pars = new List<DocumentObject>();
Spire.Doc.Document subdoc = _templateLoader.LoadTemplate(TemplatePath);
RunMacros(subdoc);
foreach (Section section in subdoc.Sections)
{
foreach (DocumentObject obj in section.Body.ChildObjects)
pars.Add(obj);
}
TextSelection ts = doc.FindString(macro, false, true);
if (ts != null)
{
TextRangeLocation trl = new TextRangeLocation(ts.GetAsOneRange());
if(trl != null)
ReplaceMacroWithBlock(trl, pars);
}
subdoc.Close();
subdoc = null;
}
private void ReplaceMacroWithBlock(TextRangeLocation location, IList<DocumentObject> pars)
{
int replacementIndex = GetReplacementIndex(location);
foreach (DocumentObject obj in pars)
{
if (obj is Table)
{
sectionBody.ChildObjects.Insert(replacementIndex, ((Table)obj).Clone()); // Exception thrown
}
}
}
When Table.Clone() is called, I receive an exception:
- Code: Select all
System.NullReferenceException: Object reference not set to an instance of an object.
at Spire.Doc.Table.CloneImpl()
at Spire.Doc.Table.Clone()
at WebCOBRA2.Letters.LetterParser.ReplaceMacroWithBlock(TextRangeLocation location, IList`1 pars) in
...
Can you please help me fix this error or provide a new release which fixes it? This code looks like it should work.