I am trying to replicate this example of calling IronPython code from VB.net. I've downloaded and installed IronPython and created a VB.net console application. I added references to all of the dlls in the IronPython installation folder:
- IronPython
- IronPython.Modules
- IronPythonTest
- Microsoft.Scripting.ExtensionAttribute
- Microsoft.Scripting
- Microsoft.Scripting.Core
And I have this source code:
Option Explicit On
Option Strict On
Imports Microsoft.Scripting.Hosting
Imports Microsoft.Scripting
Imports IronPython.Hosting
Imports IronPython.Runtime.Types
Module Module1
Public Class HelloWorldVB
Public Overridable Function HelloWorld(ByVal name As String) As String
Return String.Format("Hello '{0}' from Visual Basic", name)
End Function
End Class
Sub Main()
Dim helloWorld As New HelloWorldVB()
Console.WriteLine(helloWorld.HelloWorld("Maurice"))
Dim runtime As ScriptRuntime = PythonEngine.CurrentEngine.Runtime
Dim scope As ScriptScope = Runtime.ExecuteFile("HelloWorld.py")
Dim pythonType As PythonType = scope.GetVariable(Of PythonType)("HelloWorldIronPython")
helloWorld = CType(Runtime.Operations.Call(pythonType), HelloWorldVB)
Console.WriteLine(helloWorld.HelloWorld("Maurice"))
Console.ReadLine()
End Sub
End Module
I receive the error "Name 'PythonEngine' is not declared."
I can't seem to find PythonEngine when I search the ObjectBrowser.
Is the example out of date or do I have an error?