Using MSscriptControl in VB.net adding an object gives Specified cast is not valid error

730 Views Asked by At

Here a sample code that produces the error. I have used MSscript in VB projects in the past and those projects are functioning.

The error reported is: "When casting from a number, the value must be a number less than infinity"

Or if anyone has another suggested way to easily add scripting to a project.

    Private Sub Run_Script()
        Dim scriptEngine As New MSScriptControl.ScriptControl()
        Dim TestClass As New Sample
        Dim ScriptCode As String

        scriptEngine.Language = "VbScript"
        scriptEngine.AddObject("Test", TestClass, True)

        ScriptCode = "MsgBox ""tests"" "
        scriptEngine.AddCode(ScriptCode)
    End Sub
End Class

Public Class Sample
    Public Sub Test()
        MessageBox.Show("This is a test")
    End Sub
End Class
1

There are 1 best solutions below

0
On

I found the answer. I needed to set com visible to true. This is found under "Assembly Information"