Method Not Found Error

I am trying to generate a word document from a template using range.replace. Some of the replace has html and need to format it correctly. I am trying to use Ireplacingcallback. at splitrun method run.parentnode.insertafter the following error is raised.

System.MissingMethodException: Method not found: 'Aspose.Words.Node Aspose.Words.CompositeNode.InsertAfter(Aspose.Words.Node, Aspose.Words.Node)'.
   at ReplaceWithHtmlEvaluator.SplitRun(Run run, Int32 position) at ReplaceWithHtmlEvaluator.Aspose.Words.Replacing.IReplacingCallback.Replacing(ReplacingArgs e) .

Any thoughts what exactly is wrong here would be appreciated.

The following is text to be replaced

<p><span style="color: rgb(33, 37, 41); font-family: Oswald, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 700; letter-spacing: 0.32px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none;">Key Required Skills</span></p>

@siva_Gaddipati

What is happening

CompositeNode.InsertAfter is a public method of Aspose.Words [2][5]. The method’s signature expects the node to be inserted as the first argument and the reference node (the node after which the insertion should occur) as the second argument [3].

The MissingMethodException you see indicates that, at runtime, the loaded Aspose.Words assembly does not contain a method with the expected signature. This can occur when the version of Aspose.Words that is actually loaded differs from the version against which the code was compiled, or when the call is made with the arguments in the wrong order, causing the CLR to look for a different overload.

How to address it

  1. Check the version that is being loaded

    Console.WriteLine(typeof(Aspose.Words.CompositeNode).Assembly.FullName);
    

    Verify that the version printed matches the version you referenced in your project (preferably the latest release).

  2. Ensure the correct DLL is used at runtime

    • Replace any older copies of Aspose.Words.dll in the output folder, GAC, or other reference locations with the version you compiled against.
    • Remove duplicate or outdated copies that might be shadow‑copied.
  3. Call the method with the proper argument order

    // Example: insert a new run after the original run
    Run newRun = (Run)run.Clone(true);
    run.ParentNode.InsertAfter(newRun, run);   // first = node to insert, second = reference node
    

    This follows the documented signature [3].

  4. Re‑build and run – the MissingMethodException should no longer be thrown.

If the problem persists after confirming the DLL version and correcting the argument order, double‑check that no other copy of Aspose.Words.dll is being loaded from a different location. Feel free to share the version information you obtain from step 1 for further assistance.

@siva_Gaddipati Could you please your input and simple code that will allow us to reproduce the problem on our side? Or create a simple console application that will allow us to reproduce the problem. We will check it and provide you more information.

public MemoryStream GenerateStaffOpeningTemplate(int soId, String format)
{
    Aspose.Words.Document doc = new Aspose.Words.Document($"sotemplate.docx");
    //doc.AttachedTemplate = $"sotemplate.docx";
    var xx = typeof(Aspose.Words.CompositeNode).Assembly.FullName;
    #region read data from Database
    var soInfo = GetStaffOpeningDto(soId);            
   
    FindReplaceOptions options = new FindReplaceOptions(FindReplaceDirection.Forward);            
    options.ReplacingCallback = new  ReplaceWithHtmlEvaluator(soInfo.KeyRequiredSkills);
    doc.Range.Replace("<<keyrequiredskills>>", string.Empty, options);
    options.ReplacingCallback = new ReplaceWithHtmlEvaluator(soInfo.Responsibilities);
    doc.Range.Replace("<<responsibilities>>",  "", options);
    options.ReplacingCallback = new ReplaceWithHtmlEvaluator(soInfo.BasicQualifications);
    doc.Range.Replace("<<basicqualifications>>", "", options);
    options.ReplacingCallback = new ReplaceWithHtmlEvaluator(soInfo.RequiredSkills);
    doc.Range.Replace("<<requiredskills>>", "", options);
    options.ReplacingCallback = new ReplaceWithHtmlEvaluator(soInfo.DesiredSkills);
    doc.Range.Replace("<<desiredskills>>", "", options);
    options.ReplacingCallback = new ReplaceWithHtmlEvaluator(soInfo.ScreeningQuestions);
    doc.Range.Replace("<<screeningquestions>>", "" , options);
    #endregion

    System.IO.MemoryStream dstStream = new System.IO.MemoryStream();
   doc.Save(dstStream, SaveFormat.Docx);
    dstStream.Position = 0;
    return dstStream;

}

internal class ReplaceWithHtmlEvaluator : IReplacingCallback
{
    private string _html = "";

    internal ReplaceWithHtmlEvaluator(string html)
    {
        _html = html;
    }

    //This simplistic method will only work well when the match starts at the beginning of a run. 
    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = e.MatchNode;

        // The first (and may be the only) run can contain text before the match,
        // in this case it is necessary to split the run.
        if (e.MatchOffset > 0)
            currentNode = SplitRun((Run)currentNode, e.MatchOffset);

        // This array is used to store all nodes of the match for further removing.
        ArrayList runs = new ArrayList();

        // Find all runs that contain parts of the match string.
        int remainingLength = e.Match.Value.Length;
        while (
            (remainingLength > 0) &&
            (currentNode != null) &&
            (currentNode.GetText().Length <= remainingLength))
        {
            runs.Add(currentNode);
            remainingLength = remainingLength - currentNode.GetText().Length;

            // Select the next Run node.
            // Have to loop because there could be other nodes such as BookmarkStart etc.
            do
            {
                currentNode = currentNode.NextSibling;
            }
            while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));
        }

        // Split the last run that contains the match if there is any text left.
        if ((currentNode != null) && (remainingLength > 0))
        {
            SplitRun((Run)currentNode, remainingLength);
            runs.Add(currentNode);
        }

        DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);
        builder.MoveTo((Run)runs[0]);

        // Replace '<CustomerName>' text with a red bold name.
        builder.InsertHtml(_html);

        foreach (Run run in runs)
            run.Remove();

        return ReplaceAction.Skip;
    }

    private static Run SplitRun(Run run, int position)
    {
        Run afterRun = (Run)run.Clone(true);
        afterRun.Text = run.Text.Substring(position);
        run.Text = run.Text.Substring((0), (0) + (position));
        run.ParentNode.InsertAfter(afterRun, run);
        return afterRun;
    }
}

Input is

<p><span style="color: rgb(33, 37, 41); font-family: Oswald, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 700; letter-spacing: 0.32px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none;">Key Required Skills</span></p>

version is 25.9.0.0
running it from local in Visual Studio

@siva_Gaddipati Could you please also attach your input template document?

Also, please try changing find/replace defection from forward to backward. This might resolve the problem because in your IReplacingCallback the document node structure is modified and replacing in forward direction might cause the problems in such case.

Switching from froward to backward did not make any difference.
unable to attach file, This how it looks like
Any additional Interview information we should know?

<<additiopnalinformation>>

Screening Questions:

<<screeningquestions>>

Job Description:

<<keyrequiredskills>>

If this sounds like a mission you want to be a part of, keep reading!

DAY TO DAY RESPONSIBILITIES

<<responsibilities>>

FOUNDATION FOR SUCCESS (Basic Qualifications)

<<basicqualifications>>

FACTORS TO HELP YOU SHINE (Required Skills)

<<requiredskills>>

HOW TO STAND OUT FROM THE CROWD (Desired Skills)

<<desiredskills>>

@siva_Gaddipati Thank you for additional information. Unfortunately, I cannot reproduce the problem on my side using the following simple code:

string html = @"<p><span style=""color: rgb(33, 37, 41); font-family: Oswald, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 700; letter-spacing: 0.32px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none;"">Key Required Skills</span></p>";

Document doc = new Document(@"C:\Temp\in.docx");

FindReplaceOptions options = new FindReplaceOptions(FindReplaceDirection.Forward);
options.ReplacingCallback = new ReplaceWithHtmlEvaluator(html);
doc.Range.Replace("<<keyrequiredskills>>", string.Empty, options);
options.ReplacingCallback = new ReplaceWithHtmlEvaluator(html);
doc.Range.Replace("<<responsibilities>>", "", options);
options.ReplacingCallback = new ReplaceWithHtmlEvaluator(html);
doc.Range.Replace("<<basicqualifications>>", "", options);
options.ReplacingCallback = new ReplaceWithHtmlEvaluator(html);
doc.Range.Replace("<<requiredskills>>", "", options);
options.ReplacingCallback = new ReplaceWithHtmlEvaluator(html);
doc.Range.Replace("<<desiredskills>>", "", options);
options.ReplacingCallback = new ReplaceWithHtmlEvaluator(html);
doc.Range.Replace("<<screeningquestions>>", "", options);
            
doc.Save(@"C:\Temp\out.docx");

I used the following template for testing: in.docx (14.4 KB)

If possible, please create a simple console application that will allow us to reproduce the problem on our side. We will check it and provide you more information.