2009-06-30 5 views
0

Ich versuche this example of calling IronPython Code von VB.net zu replizieren. Ich habe IronPython heruntergeladen und installiert und eine VB.net-Konsolenanwendung erstellt. Ich habe Verweise auf alle DLLs in der Ironpython-Installationsordner:Aufruf von IronPython über VB.net - "Name 'PythonEngine' wird nicht deklariert."

  • Ironpython
  • IronPython.Modules
  • IronPythonTest
  • Microsoft.Scripting.ExtensionAttribute
  • Microsoft.Scripting
  • Microsoft. Scripting.Core

Und ich habe th ist Quellcode:

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 

Ich erhalte den Fehler "Name 'PythonEngine' wird nicht deklariert."

Ich kann PythonEngine nicht finden, wenn ich den ObjectBrowser suche.

Ist das Beispiel veraltet oder habe ich einen Fehler?

Antwort

0

Die Dinge scheinen sich geändert zu haben.

Ich habe nicht auf IronPython & gearbeitet haben es jetzt heruntergeladen.
Ich habe versucht, Ihren Code mit Bezug, was in IronPython.DLL ist

  • In Bezug auf IronPython.dll
  • Anweisung hinzufügen für Importe - "Imports IronPython.Hosting".

Dim scriptEngine as Python.CreateEngine()
Dim scope As ScriptScope = scriptEngine.ExecuteFile("myfile.py")

Ich denke, Rest des Codes funktionieren sollte, wie es ist.
Laden Sie die Ironpython.dll in Reflektor & Sie können die Typen/Methoden/Eigenschaften sehen.

Hoffe, dass hilft.

Verwandte Themen