locked
MSScriptControl throws a Specified cast is invalid exception RRS feed

  • 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

All replies