I created a Class Library project in Visual Studio 2010 and created added the following VB.Net class:
Public Class Dumb
Private name As String
Public Sub New(ByVal newName As String)
name = newName
End Sub
Public Sub sayHi()
System.Console.WriteLine("Hi " & name)
End Sub
End Class
I built the solution and generated a DLL file (say PATH_TO_NEW_DLL).
In IronPython, I get the error below when I try to clr.AddReferenceToFileAndPath(PATH_TO_NEW_DLL). The file DOES exist on my computer.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: System.IO.IOException: file does not exist: [PATH_TO_NEW_DLL]
at IronPython.Runtime.ClrModule.AddReferenceToFileAndPath(CodeContext context, String file)
at IronPython.Runtime.ClrModule.AddReferenceToFileAndPath(CodeContext context, String[] files)
at Microsoft.Scripting.Utils.ActionHelper`2.Invoke(Object arg0, Object arg1)
at Microsoft.Scripting.Utils.ReflectedCaller.Invoke(Object[] args)
at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[] args, Boolean& shouldOptimize)
at IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`2.Call1(CallSite site, CodeContext context, TFuncType func, T0 arg0)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at <unnamed>$28.<unnamed>(CodeContext $globalContext, FunctionCode funct开发者_运维知识库ionCode) in <stdin>:line 1
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass1.<RunOneInteraction>b__0()
Use a relative path to your startup file. Here is an example:
In one of my projects, the startup file (the one that has the green "play" icon in your solution explorer) was in a folder that had another folder PMX
in it. Inside the PMX
folder was the DLL I was trying to access. This DLL had the PMXlib
namespace in it. The PMXlib
namespace had a class called "PMX
".
So, the directory structure is as follows:
PMX\
PMXlib.dll
main.py
This is the code I used to access the PMX
class inside the PMXlib
DLL.
import clr
clr.AddReferenceToFileAndPath("PMX\PMXlib.dll")
from PMXlib import PMX
#PMXlib is the namespace name. PMX is the class name inside the DLL.
精彩评论