Context: Windows Azure; Visual Studio Community 2015; ClearScript; JScript
I'm having problems exposing an XmlDocument object to the JScripts I'm executing using ClearScript.
I am instantiating a JScript interpreter using
JScriptEngine JSengine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableJITDebugging);
To instantiate the XmlDocument object I have tried both
using System.Xml;
...
JSengine.AddHostType("CSXmlDocument", typeof(XmlDocument));
...
and
...
JSengine.AddCOMObject("CSXmlDocument", "MSXML2.DOMDocument");
...
and I execute the JScript script using this
...
object answer = JSengine.Evaluate(File.ReadAllText(rulesetFilename));
...
My difficulty is in how to use the CSXmlDocument
object inside the script. I have tried all of the following to no avail.
var xmlObj1 = CSXmlDocument;
var xmlObj2 = new CSXmlDocument;
var xmlObj3 = CSXmlDocument();
var xmlObj4 = new CSXmlDocument();
When CSXmlDocument
is defined using AddCOMObject
, the second through fourth invocations give an error of
Unable to evaluate the expression. Operation not supported. Unknown error: 0x8013baff.
The first invocation only gives me access to three methods, Equals
, GetHashCode
, GetType
.
When CSXmlDocument
is defined using AddHostType
, the first gives just the three methods as above. The second invocation seems to give access to the full set of properties and methods (at least that's what VS2015 says in a debugging session) however, when I try to use the LoadXml
method I get
xmlObj2.LoadXml(body)
Unable to evaluate the expression. Operation not supported. Unknown error: 0x8013baff.
I am currently working through two possible gotchas:
- Character encoding, in the light of another StackOverflow posting.
- HTML-XML markup conflicts.