Answered by:
MSScriptControl throws a Specified cast is invalid exception

Question
-
I have an existing VB6 program that uses the MSScriptControl to enable our users to insert Exit processing in our product. I could not find anything in .NET that supports scripting. If there is, please let me know. Otherwise I will have to find a way to make this work.
There are three class modules defined in the project. Objects are created of each type and they are made available to the script using the AddObject method. Here are the relevant statements leading to the problem. Excuse all the Try blocks. I was trying to figure this thing out.
fScript.Language = "VBScript"
fScript.AllowUI = False
fAssignScript = fScript.Modules.Add("SAssign")
Try
fAssignScript.AddCode(txtScript.Text)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, vbOK)
End Try
wkObject = fKMSAccount
Try
fScript.AddObject("kmsaccount", wkObject)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, vbOK)
End Try
Try
fScript.AddObject("KMSSuspects", fKMSSuspects)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, vbOK)
End Try
The last Try block tripped the exception the produced the Specified cast is invalid. At first I tried this without the wkObject, and got the same results. Forcing fKMSAccount into an Object variable, which is what the intellisense says is expected there did not make any difference at all. So what is the problem and how can I get this to work?There is no "Ask a question" button in the Visual Studio forum, and when I go one level up to the Developer (Partner) Forums, the forum category below does not mention ANY of the forums in the list. Please post this to the correct forum and please put the Ask A Question button back into the individual forum level. This scheme was not well thought out.
Mike
Friday, February 8, 2013 2:33 AM
Answers
-
I think there may currently be problems with partner forums You could try the MSDN VS forums.
http://social.msdn.microsoft.com/Forums/en-US/category/visualstudio
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.- Marked as answer by FZBEditor Friday, March 1, 2013 9:44 AM
Friday, February 8, 2013 3:20 AM -
There is no forum here for VB6 controls. You can try http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/threads.
Visual C++ MVP- Proposed as answer by Ed Price - MSFTMicrosoft employee Sunday, February 17, 2013 9:27 AM
- Marked as answer by FZBEditor Friday, March 1, 2013 9:43 AM
Friday, February 8, 2013 4:18 AM
All replies
-
I think there may currently be problems with partner forums You could try the MSDN VS forums.
http://social.msdn.microsoft.com/Forums/en-US/category/visualstudio
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.- Marked as answer by FZBEditor Friday, March 1, 2013 9:44 AM
Friday, February 8, 2013 3:20 AM -
There is no forum here for VB6 controls. You can try http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/threads.
Visual C++ MVP- Proposed as answer by Ed Price - MSFTMicrosoft employee Sunday, February 17, 2013 9:27 AM
- Marked as answer by FZBEditor Friday, March 1, 2013 9:43 AM
Friday, February 8, 2013 4:18 AM