Why can’t I assign a type to ScriptSettings?

JohnnyRoy wrote on 7/25/2004, 12:05 PM
The following line of code:
var rootElement = ScriptSettings.DocumentElement;
MessageBox.Show(rootElement);
Displays: System.Xml.XmlElement

By I like knowing what type all of my variables are so I always type my variables. Therefore the following "cleaner" line of code should work:
var rootElement : System.Xml.XmlElement = ScriptSettings.DocumentElement;
MessageBox.Show(rootElement);
But it doesn’t! Instead it just displays:

Error: Specified cast is not valid.

The same holds true for ScriptSettings itself which claims its an XmlDocument yet it can’t be cast to an XmlDocument. This also prevents you from passing it into a C# DLL as a parameter because it can’t be typed.

Does anyone know what’s going on here?

~jr

Comments

rcampbel wrote on 7/26/2004, 8:09 AM
I ran into this problem as well a while back. I gave up using the ScriptSettings parm and just wrote code to read the config file into an XmlDocument myself.

Here is the C# code that I use:

XmlDocument scriptSettings = new XmlDocument();
XmlTextReader reader = new XmlTextReader(configFile);
scriptSettings.Load(reader);
reader.Close();

Set configFile to the name of the config file.

Randall
JohnnyRoy wrote on 7/26/2004, 4:07 PM
Randall,

Yea, that was my next option; just using my own XML file. Thanks for the code. I find the JScript host to be the strangest environment to develop in.

~jr