This project has moved. For the latest updates, please go here.

class not defined error

Apr 1, 2015 at 4:00 PM
Edited Apr 1, 2015 at 4:03 PM
hi,

So I have this VB script:
productOverride = New ProductValueOverride
productOverride.NewValue = 2
productOverride.ProductId = 24
And I am getting a 'Class not defined: ProductValueOverride'. But I put a break point right before executing the script and looking at the field 'hostItemMap' and the class is there with the exact same spelling.

Any ideas on what can be wrong?
Is there a different syntax to instantiate clr classes?
Coordinator
Apr 1, 2015 at 5:25 PM
Hello!

Unfortunately VBScript's New operator works only on VBScript classes. To instantiate a CLR class, you have to use HostFunctions.newObj:
engine.AddHostObject("host", new HostFunctions());
engine.AddHostType("Dictionary", typeof(Dictionary<string, object>));
engine.Execute(@"
    dict = host.newObj(Dictionary)
    dict.Add ""abc"", 123
");
Cheers!
Apr 2, 2015 at 1:53 PM
Awesome, now it works