开发者

Being unable to use functions from dll file in ASP.NET IronPython

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 i开发者_开发技巧mport *

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


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 ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜