views:

29

answers:

1

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 functionCode) 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()
A: 

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.
Aphex
According to http://msdn.microsoft.com/en-us/library/17k74w0c.aspx, "Because class libraries do not have an entry point, their only option for this property is (None)." Is there a difference between the startup file you are referring to and the startup object in VS2010?
ravi77o
This is what I meant: http://imgur.com/RbeZY.pngAs you can see, `app.py` is my current startup file (it has a green icon on it) and I can change the startup file by right clicking any other file. This merely changes what .py file is sent to ipy.exe to start your program.
Aphex
I noticed that you are referring to the fact that you're making a class library (presumably to be used from other apps). In that case see if you can use the DLL from the same folder as the class library.
Aphex
I am trying to clr.AddReferenceToFill("DumbLib.dll") from the same parent directory as "DumbLib.dll", but I get System.IO.IOException: Could not add reference to assembly DumbLib.dll. (btw, thanks for your help! I'm not a VB or .Net developer, so my terminology might be off)
ravi77o