I found a strange problem with the old fashioned MS Script Control and have
no clues what this is about.
In a VB.NET app, I used this code:
Dim sc As New MSScriptControl.ScriptControl
sc = CreateObject("ScriptControl")
sc.Language = "VBScript"
sc.AddObject("myObj", "Hello World!", True)
'sc.AddObject("myObj", New ComClass1, True)
sc.AddCode("MsgBox myobj.toString")
[Note that to reproduce this code, you will need to add a reference to the
COM object Microsoft Script Control (MSScriptControl).]
The funny thing is AddObject, where I add a string as object which works
since strings are objects.
So in essence, I export a .NET object to the COM script environment and call
its "toString" from script.
What I really want of course is adding my own .NET class ComClass1 (see
commented out line). However, this always fails with an "invalid cast
exception".
No matter what I try, I can only add intrinsic .NET objects but none of
mine.
This is strange since many users have reported on Newsgroups they used
successfully something like this to add the entire form to the script object
model:
sc.AddObject("myObj", me, True)
In my case, however, this also creates the exception.
I am using VS 2005 and Framework 2.0. Are there maybe changes in design?
Could someone with the retail version check my code and see if it works in
Framework 1?
As it seems, objects need to meet certain requirements to add them via
AddObject. I have no clue though which requirements this are and how to meet
them. Can anyone help?
Thanks a lot folks!

Signature
__________________________________
Dr. Tobias Weltner
MVP Windows Server / Scriptautomation
Tobias Weltner - 21 Jun 2005 09:36 GMT
Please cut out the line with "CreateObject" in it, it shouldn't be in there.
The problem remains, though...

Signature
__________________________________
Dr. Tobias Weltner
MVP Windows Server / Scriptautomation
Tobias Weltner [MVP] - 23 Jun 2005 08:18 GMT
So I'll answer my question:
In VS 2005, assembly information isn't COM visible by default anymore.
Change it, and it works...