没有这样的方法:org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()C#/ docx4j.NET中的ILoggerFactory / invokeVirtual

时间:2018-02-08 18:12:44

标签: c# docx4j

我在java / Maven中发现了一些关于此消息的点击,但我使用的是C#/ VisualStudio,因此他们的答案不能直接应用。该项目是C#,.NET 4.5 Console项目,我使用nuget:

install-package doc4j.net

我有这段代码:

    try
    {
        string projectDir = @"C:\project\samples\";
        ILog log = LogManager.GetCurrentClassLogger();
        log.Info("Hello from Common Logging");
        System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(org.slf4j.impl.StaticLoggerBinder)); 

        ikvm.runtime.Startup.addBootClassPathAssembly(
            System.Reflection.Assembly.GetAssembly(
                typeof(org.slf4j.impl.StaticLoggerBinder))); 

        // Configure to find docx4j.properties
        // .. add as URL the dir containing docx4j.properties (not the file itself!)
        Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(@"C:\project\samples\resources\");

        fileIN = projectDir + @"P0009.docx";
        java.io.File javaFile = new java.io.File(fileIN);
        WordprocessingMLPackage wordDoc = WordprocessingMLPackage.load(javaFile); // Exception occurs here.

        MainDocumentPart mainPart = wordDoc.getMainDocumentPart();
        Console.WriteLine(mainPart.getXML());
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }

在注释行,我得到了例外:

Message=The type initializer for 'org.docx4j.openpackaging.packages.WordprocessingMLPackage' threw an exception.

最内层的例外是:

Message=no such method: org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()ILoggerFactory/invokeVirtual
Source=IKVM.OpenJDK.Core

我发现的所有帖子都说有涉及slf4j的版本不匹配,解决方法是修改vom.xml来控制依赖关系。由于这是VisualStudio,显然这不是答案。不仅如此,还要查看项目中安装的文档化依赖项和版本(docx4j v3.3.2.81,IKVM v8.1.5717.0,Common.Logging v2.1.2.0和slf4j v1.7.5.4) #39;无论如何都适用。所以问题很简单:我如何摆脱这个错误?

1 个答案:

答案 0 :(得分:0)

实际上,如果您注释掉以下内容,它似乎有效:

    //ikvm.runtime.Startup.addBootClassPathAssembly(
        //System.Reflection.Assembly.GetAssembly(
           //typeof(org.slf4j.impl.StaticLoggerBinder)));