ScriptSettings Problem

rcampbel wrote on 5/7/2004, 2:12 PM
I am having a problem using the ScriptSettings global variable. I write my scripts using C# and compile them into a dll. Then I use the .config file AssemblyReference tag to have the Vegas script engine load my dll.

I can't pass the ScriptSettings global variable to the C# code. If I specify the type of the argument on the C# method as System.Xml.XmlDocument, eg:

public static void Hello(XmlDocument ScriptSettings)

I get he following exception:

Microsoft.Vsa.VsaException: UnknownError (0x801330FF): System.InvalidCastException: Specified cast is not valid.

I can pass the object to the C# code if I specify the type of the argument on the C# method as object. I.e.

public static void Hello(object ScriptSettings);

However, when I then try to cast it to an XmlDocument, I get the invalid cast exception.

I have verified that the type of ScriptSettings once passed to C# is System.Xml.XmlDocument, but I still can't cast it to that type.

Any ideas?

Thanks,

Randall Campbell

Comments

SonyPJM wrote on 5/10/2004, 7:54 AM

I've experienced problems using the ScriptSettings object also. After
scouring the web and news groups (several times now), I've seen
mention of similar problems in other apps but no solutions. It
appears to be a bug in the JScript engine.

The work-around I've found is to create a copy of the ScriptSettings
document in your script and pass the copy to your C# code:

var doc : XmlDocument = new XmlDocument();
doc.LoadXml(ScriptSettings.InnerXml);
MyClass.Hello(doc);


This way you can declare Hello as you would prefer:

public static void Hello(XmlDocument settingsDoc)
rcampbel wrote on 5/10/2004, 8:42 AM
Thanks. This is essentially the same work around that I came up with, except that I created another XmlDocument in the C# code by reading from the script config file again. In either case you end up with two copies of the XML in memory.

Thanks, perhaps .Net 2.0 will fix this.

Randall