TOC not finding TC Fields

Code that creates Table of Contents page:

var builder = new DocumentBuilder(reportDoc);
// Insert a table of contents
var smallRuns = reportDoc.GetChildNodes(NodeType.Run, true);
var collector = new LayoutCollector(reportDoc);

var pageIndex = 2;
foreach (Run run in smallRuns)
{
    if (collector.GetStartPageIndex(run) == pageIndex)
    {
        builder.MoveTo(run);
        builder.Font.Size = 30;
        builder.Font.Bold = false;
        builder.Writeln("Table Of Contents");
        builder.Writeln("");
        builder.InsertTableOfContents("\\f \\l \"1-3\"");
        break;
    }
}

builder.InsertBreak(BreakType.PageBreak);
reportDoc.UpdateFields();

Word docx snippet with field:

@brooksclarkpwc Unfortunately, I am unable to preproduce the problem on my side. Could you please attach your document here for testing? We will check the issue and provide you more information.
I have used the following simple code for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertTableOfContents("\\f \\l \"1-3\"");
builder.InsertBreak(BreakType.PageBreak);
builder.InsertField("TC \"Chapter Details\" \\l 1");
builder.Write("Chapter Details");
doc.UpdateFields();
doc.Save(@"C:\Temp\out.docx");

Hmmm. Guess it is finding the TC Field. When I remove the field, the TOC complains:

So the question now is, why does the TOC not generate when the tag is in place? (Report goes from cover page to first content page without a Table of Contents in between when the TC Field is inserted. Image above is from page 2 Table of Contents when TC Field is NOT inserted)

@brooksclarkpwc Most likely, the TOC complains because there is no items to build the TOC from. Could you please attach your problematic document here for our reference? We will check it and provide you more information.

I moved the TC Field insertion to after the heading paragraph, now TOC finds the fields.

Now my problem is the TOC text is different colors. I think I need to set the color in TOC2

Here is the code that creates our headings and TC Fields:

public static void BuildSectionHeading(Document doc, string text)
{
    var builder = new DocumentBuilder(doc);
    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
    builder.Font.Size = 30;
    builder.Font.Bold = false;
    builder.Font.Name = "Georgia";
    builder.Font.Color = Color.FromArgb(208, 74, 2);
    builder.Writeln(text);
    builder.InsertField($"TC \"{text}\" \\f t \\l 2");
}

Yet the TOC lines are rendering some Black, others Orange.

@brooksclarkpwc TOC items inherit formatting from TC fields. So you can modify your code like this:

builder.Writeln(text);
builder.Font.ClearFormatting();
builder.InsertField($"TC \"{text}\" \\f t \\l 2");

Or even use heading paragraphs instead of TC fields to build TOC:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
builder.InsertBreak(BreakType.PageBreak);

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Font.Size = 30;
builder.Font.Bold = false;
builder.Font.Name = "Georgia";
builder.Font.Color = Color.FromArgb(208, 74, 2);
string text = "Some Heading";
builder.Writeln(text);

doc.UpdateFields();

doc.Save(@"C:\Temp\out.docx");