Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

ScriptControl cast exception with managed classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tobias Weltner - 21 Jun 2005 09:28 GMT
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...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.