views:

296

answers:

1

Hi,

I have a file like this compiled into a dll file and placed in the bin folder

1

Imports System
Imports System.Web

Namespace Conexiones       
     Public Class sql_conexiones
       Shared Sub consulta..
           ...

By doing

from Conexiones import *

from the .aspx.py file it works fine.

I have this other file in the APP_SCRIPT in a py file (no namespaces declared)

2

import clr
clr.AddReference('System')
import System
clr.AddReference('System.Data')
from System.Data import * 
clr.AddReference('System.Web')
import System.Web

def consulta ...

By doing

from funciones import * 

from the .aspx.py file it works fine.

Now I want the code from funciones in a dll file. I have funciones.dll in the bin folder and I have

from funciones import * 

in the .aspx.py .

I get "no module named funciones" May be I have to explicity add the dll? I do

clr.AddReference("funciones.dll") 
from funciones import *

and I get "Could not add reference to assembly funciones.dll"

My question is, How do I have to do to be able to use functions in a file with code similar to #2, placed in a dll file in the bin folder in ASP.NET IronPython? The only difference I see between #1 and #2 is #1 has a namespace declared

A: 

I think you have two options:

  1. Try to use AddReferenceToFile(str) or AddReferenceToFileAndPath(str). See this mail for explanation.

  2. Insert bin\ to sys.path and then try to add the reference.


Added:

The idea of compiling IronPython code is as follows:

You have a file func.py:

def one():
    return 1

You compile it with pyc.py:

C:\IronPython-2.6\ipy.exe C:\IronPython-2.6\Tools\Scripts\pyc.py /out:funciones /target:library func.py

You use it in another script:

import clr
clr.AddReference('funciones')
import func
print func.one()

I hope you see the difference between func and funciones ;-)

Lukas Cenovsky
I loaded it using AddReferenceToFileAndPath(str) and it got no error. But when I do "from funciones import *" I get "no module named funciones" . If I create a funciones.dll file out of a funciones.py file shouldnt the module name only be funciones ?
Pablo
The question is how do you compile funciones.dll. I have added some example to my answer.
Lukas Cenovsky
Still not working. But the 2 assemblies I mentioned before are listed differently in the object explorer. The first (the one which works, made from a VB.NET code file) says "Namespace conexiones, member of conexiones" and the second (the one I cant import the module) says "Public class DLRcachedCode member of funciones"
Pablo
It would seem in the dll made from the IronPython code file there is no namespace
Pablo
Well, if it works from script but not from ASP page, then it probably cannot be done. Dll compiled by pyc.py is not standard .NET .dll - you cannot use it from C# or VB, you can use it only form IronPython.
Lukas Cenovsky
The thing is, I want to use an IronPython dll from an IronPython asp.net project :) But I might be stuck in some silly mistake and I just cant see it. Could you use IronPython dlls in IronPython asp.net projects without any problem? Do you see the namespaces from the IronPython dlls listed correctly or do you also see "public class DLRCachedCode" instead of a Namespace? :)Sorry if I wasnt clear enough, it might be due to Im not native english speaking person :)
Pablo
Unfortunately I haven't tried IronPython with ASP.NET. You will always see DLRCachedCode in compiled IronPython files - you cannot put there your namespace. That's why you cannot use such .dlls directly in you C# or VB code - you can use them only via IronPython Engine.
Lukas Cenovsky
You have some dlls made from IronPython codefiles working I assume, Which IDE are you using? Which framework? (Winforms, Windows Presentation Foundation, etc?) I want to try the same dll in another enviroment to see if I get the same problem there :) –
Pablo
You can try the example above. Or check my blog: http://gui-at.blogspot.com/ I use WPF and Silverlight. Dlls made with pyc.py does not work with Silverlight - tt's known issue: http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=25680
Lukas Cenovsky
well aparently they dont work in asp.net either. What do you do to protect your code in SilverLight? You just leave them open? :)
Pablo
Aparently, for asp.net the modules work if you compile the py files with clr.CompileModules().
Pablo