C++ CLI Saxon .NET gives error : java.lang.IllegalArgumentException: 'Externally supplied NodeInfo belongs to the wrong Configuration'

C++ CLI Saxon .NET gives error : java.lang.IllegalArgumentException: 'Externally supplied NodeInfo belongs to the wrong Configuration'

C++代码:

void applyXslt(Saxon::Api::XdmNode^ fxmlFile, Saxon::Api::XsltTransformer^ xsltFile, const std::string& outputFile)
{
    // Apply the xslt to the cached xml
    auto processor = gcnew Saxon::Api::Processor(false);

    xsltFile->InitialContextNode = fxmlFile;
    auto serializer = processor->NewSerializer();    \ Error occurs here

    System::String^ output = gcnew System::String(outputFile.c_str());
    serializer->SetOutputFile(output);

    xsltFile->Run(serializer);

}

创建序列化器不知何故失败,我创建测试项目时它工作,但现在它似乎不工作。这是 Saxon 中的错误吗??

为了让您将问题标记为已回答,我总结了评论中似乎有帮助的内容。

一般来说,Processorclass是中枢,见https://www.saxonica.com/html/documentation10/dotnet/dotnetapi.html说法

The first thing the application needs to do is to create a Processor. The Processor holds configuration information for Saxon, and shared resources such as the name pool and schema pool. It is possible to run multiple processors concurrently if required, but it is usually more economical for all Saxon processes within a single application to use the same Processor.

因此,基于此,您的代码应该保留您用来创建 XdmNodeXsltTransformerProcessor,您已经将其传递给函数 applyXslt 并且传递该处理器实例以及一个参数,然后使用它来创建 Serializer.