Getting the error "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found" in the unit test, but not in the main program

I am creating a C # application that uses com.gargoylesoftware.htmlunit.WebClient to access and retrieve information from web pages.

My application works fine with the main project, but when I try to build unit tests to test project classes, I get the following error:

FactoryConfigurationError Message "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found" Source "IKVM.OpenJDK.XML.API" string StackTrace " at javax.xml.parsers.DocumentBuilderFactory.newInstance() at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration(Reader configurationReader) at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration() at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration..ctor(BrowserVersion ) at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(BrowserVersion browserVersion) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine..ctor(WebClient webClient) at com.gargoylesoftware.htmlunit.WebClient.init(BrowserVersion , ProxyConfig ) at com.gargoylesoftware.htmlunit.WebClient..ctor(BrowserVersion browserVersion) at com.gargoylesoftware.htmlunit.WebClient..ctor() at GWT.HeadlessBrowser..ctor() in C:\\hg\\EXE\\GWT\\HeadlessBrowser.cs:line 57 at TestGWT.ProgramTest.TestLogInProcessForGWT() in C:\\hg\\TestGWT\\ProgramTest.cs:line 115" 

Attempting to create the HtmlUnit web client in the unit test class also causes this error.

I have links to htmlunit-2.7, IKVM.OpenJDK.Core and IKVM.OpenJDK.XML.API projects both in the main project and in the project containing unit test.

Do I need an additional project link for unit test? What can cause this error?

The test class uses Microsoft.VisualStudio.TestTools.UnitTesting;

+7
source share
2 answers

I ran into the same problem quite recently while testing the same library. I found that including a link to IKVM.OpenJDK.XML.Parse.dll solved the problem.

+17
source

I ran into a similar problem.

It seems the class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl is not loaded, so the factory cannot create it. Adding this line before calling factory causes the assembly to load, and then factory can see it, and everything works as expected ...

 com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl s = new com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl (); 
+5
source

All Articles